File Name issue
dn
PythonList at DancesWithMice.info
Sun Oct 18 04:00:18 EDT 2020
On 18/10/2020 12:58, Mladen Gogala via Python-list wrote:
> On Sat, 17 Oct 2020 22:51:11 +0000, Mladen Gogala wrote:
>> On Sat, 17 Oct 2020 18:12:16 -0400, Steve wrote:
>>
>>> with open("HOURLYLOG.txt", 'r') as infile:
>>> works but, when I rename the file, the line:
>>> with open("HOURLY-LOG.txt", 'r') as infile:
>>> does not. The complaint is: Cannot Assign to operator
>>> with open( "HOURLY-LOG.txt", "r" ) as f:
... print( f.read() )
...
yes
^^^ the entire contents of a magnificent test-file
NB:
Python 3.8.5 (default, Aug 12 2020, 00:00:00)
[GCC 10.2.1 20200723 (Red Hat 10.2.1-1)] on linux
> BTW, I used this
> cp /var/log/syslog ./in-file.log
> #!/usr/bin/env python3
> import io
> with open("in-file.log","r") as infile:
> for line in infile:
> print(line)
> I got a different error:
> Traceback (most recent call last):
> File "./test.py", line 4, in <module>
> for line in infile:
> File "/usr/lib/python3.8/codecs.py", line 322, in decode
> (result, consumed) = self._buffer_decode(data, self.errors, final)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position 897:
> invalid continuation byte
@Mladen: is syslog a text file or binary format?
--
Regards =dn
More information about the Python-list
mailing list