classification
Title: Filtration of the .txt file
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Hamed, eric.smith, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-03-21 17:32 by Hamed, last changed 2020-03-21 20:37 by Hamed. This issue is now closed.

Files
File name Uploaded Description Edit
settings.txt Hamed, 2020-03-21 18:19
settings.txt Hamed, 2020-03-21 19:48
Messages (9)
msg364763 - (view) Author: Hamed Elahi (Hamed) Date: 2020-03-21 17:32
Hello,

I saw a problem when this line of code is used in Python 3:

settings = [line for line in settings if (line!='' and line[0] != '#')]

Before updating windows, this line of code filtered the texts from the beginning of .txt file, so only the first lines remained after filtration, but now, after windows update, it filters the texts so that the last rows of .txt file will remain after filtration.
Shouldn't a line of code acts the same in different updates?
msg364764 - (view) Author: Hamed Elahi (Hamed) Date: 2020-03-21 17:34
Hello,

I saw a problem when this line of code is used in Python 3:

settings = [line for line in settings if (line!='' and line[0] != '#')]

Before updating windows, this line of code filtered the texts from the beginning of .txt file, so only the first lines remained after filtration, but now, after windows update, it filters the texts so that the last rows of .txt file will remain after filtration.
Shouldn't a line of code acts the same in different updates?
msg364765 - (view) Author: Hamed Elahi (Hamed) Date: 2020-03-21 17:37
Hello,

I saw a problem when this line of code is used in Python 3:

settings = [line for line in settings if (line!='' and line[0] != '#')]

Before updating windows, this line of code filtered the texts from the beginning of .txt file, so only the first lines remained after filtration, but now, after windows update, it filters the texts so that the last rows of .txt file will remain after filtration.
Shouldn't a line of code act the same in different updates?
msg364766 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-21 17:38
What versions of Windows were involved? Are the versions of Python the same? What's the exact version? Best would be the 2 lines you get after running python, like:

$ python3
Python 3.7.4 (default, Jul 21 2019, 14:43:25)
[GCC 7.4.0] on cygwin

Please provide a short text file that shows this problem.

Also, show us how you're opening the file.

I've never heard of a Windows update causing a problem like this, so I suspect there's something else going on.
msg364768 - (view) Author: Hamed Elahi (Hamed) Date: 2020-03-21 18:19
Windows 10 Home

Python 3.7.3 [MSC v.1916 64 bit (AMD64)] on win32

I open the file so etc.:

settings_file = open('settings.txt','r')
settings = [line.strip() for line in settings_file.readlines()]
# Filter out comments and empties
settings = [line for line in settings if (line!='' and line[0] != '#')]

I attach the .txt file.

I think the problem can be because of that line, because, before windows update, I used this .txt file and the first 4 parts of its content has been used to begin the program, but now, it sees that as None. The problem is with my new folders, when I create a new folder. It works different there, but in the old folders, it works as before.
msg364769 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-21 18:29
So are you saying that you see this problem on the current version of Windows that you're running, but whether or not you see the problem depends on if the file was created before or after you updated Windows? How are you creating these files?

Does the file you attached show the problem or not? And could you explain exactly what you're seeing, versus what you're expecting to see? It's not clear from your last message. For example, what is the value of the variable "settings", and what do you expect it to be?

If you have two files on your system which currently show the problem, please attach them both, with different names, and tell us which one shows the problem and which one doesn't.

My only guess is that this is related to encodings or line endings.
msg364771 - (view) Author: Hamed Elahi (Hamed) Date: 2020-03-21 19:48
I don't have any other windows to run on them, too. But, now, when I run .py file from older folders before updating windows, then I've got this problem or when I copy the folders and run .py file from these newly created folders.

See here:

I ran both files. See the result of filter:

First file:

['sampling:rate 0', 'sampling:depth 3', 'ch1:mapping 2', 'shared 1', 'ch1:range_i 2', 'ch2:mapping 0', 'ch2:range_i 1', 'ch1:mapping 0', 'ch1:range_i 0']


Second file:

['sampling:rate 0', 'sampling:depth 3', 'ch1:mapping 2', 'shared 1', 'ch1:range_i 2', 'ch2:mapping 0', 'ch2:range_i 1', 'ch1:mapping 0', 'ch1:range_i 0']

So, both of them give the same result after filtering, but see the result of program here:

First file:

0 0.000 -0.000000 -0.000788


Second file:

0 0.000 160095.125000 -0.000525


So, as you see, the first file has None values, because of that, I'm getting that line of code with these values: -0.000000 -0.000788

I sent an attachment before which is the file that give me the wrong result.

When I use a .txt file with 4 parts like the attachment, the program works correctly, but I wanted to know how I received different results from two folders from different times. So, It is not a big problem.

Sorry that I cannot give you more information, because I wrote this program for university, it is forbidden to send for others. And currently, I'm writing my thesis and testing new programs, so please do not reply to my message. Because I don't have time to answer the questions, now. But, when my thesis finishes after two months and I saw the problem is disturbing me another time, thus I will give you more information about it.
Thank you for your help.
msg364772 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-21 20:05
I don't see a problem here. Your first file has more lines, so it produces more output than the second file. Presumably the difference in output you see when you run your program is a result of this. But since we can't see the code, we can't know for sure.

I don't see anything to make me think this is related to what version of Windows your program is running under, or that there's a bug in python. So I'm going to close this issue. If you can produce a program that demonstrates a bug in python, you can provide more details (including the full source code) and re-open this issue.

I suggest you look for help on the python-list mailing list: https://mail.python.org/mailman/listinfo/python-list
msg364774 - (view) Author: Hamed Elahi (Hamed) Date: 2020-03-21 20:37
No, the .txt files were the same, when I sent the results.

I send another .txt file to show the different, but the results were
created with the same .txt file for both runs.

Unfortunately, it is forbidden to send .py files.

On Sat, Mar 21, 2020 at 9:05 PM Eric V. Smith <report@bugs.python.org>
wrote:

>
> Eric V. Smith <eric@trueblade.com> added the comment:
>
> I don't see a problem here. Your first file has more lines, so it produces
> more output than the second file. Presumably the difference in output you
> see when you run your program is a result of this. But since we can't see
> the code, we can't know for sure.
>
> I don't see anything to make me think this is related to what version of
> Windows your program is running under, or that there's a bug in python. So
> I'm going to close this issue. If you can produce a program that
> demonstrates a bug in python, you can provide more details (including the
> full source code) and re-open this issue.
>
> I suggest you look for help on the python-list mailing list:
> https://mail.python.org/mailman/listinfo/python-list
>
> ----------
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue40035>
> _______________________________________
>
History
Date User Action Args
2020-03-21 20:37:09Hamedsetmessages: + msg364774
2020-03-21 20:05:45eric.smithsetstatus: open -> closed
resolution: not a bug
messages: + msg364772

stage: resolved
2020-03-21 19:48:58Hamedsetfiles: + settings.txt

messages: + msg364771
2020-03-21 18:29:39eric.smithsetmessages: + msg364769
2020-03-21 18:19:50Hamedsetfiles: + settings.txt

messages: + msg364768
2020-03-21 17:38:56eric.smithsetnosy: + eric.smith
messages: + msg364766
2020-03-21 17:37:53Hamedsetmessages: + msg364765
2020-03-21 17:34:59Hamedsetmessages: + msg364764
title: ilteration of the .txt file -> Filtration of the .txt file
2020-03-21 17:32:59Hamedcreate