File Name issue

Mladen Gogala mgogala at yahoo.com
Sat Oct 17 19:58:12 EDT 2020


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
> 
> Try this:
> 
> with open("HOURLY\-LOG.txt", 'r') as infile:

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

However, that doesn't have anything to do with your problem. 

-- 
Mladen Gogala
Database Consultant
http://mgogala.byethost5.com


More information about the Python-list mailing list