A problem with opening a file

dn PythonList at DancesWithMice.info
Sun Nov 29 03:43:44 EST 2020


On 29/11/2020 20:56, Gabor Urban wrote:
> Hi,
>> I am facing an issue I was not able to solve yet. I have a class saving
> messages to a file. The relevant code is:
>> ----
>> import OS

if you're wanting the Python Standard Library, this should not be in 
upper-case
> import sys

are these two imports used elsewhere?
> class MxClass:
>> def __init__(self, fName, fMode,....):
> self.fileName = fName
> self.fileMode = fMode
> ....

names such as fName and writeMethod are valid Python, but won't pass 
PEP-8 conventions
> def writeMethod(self, message):
> data = open(self.fileName, self.fileMode)
> ....
>> ----
>> Tests reveal: the class is instantiated correctly, other methods work
> perfect. The writeMethod raises a NameError opening the file
> "name 'open' is not defined"
>> I am stuck here.....

Please review ALL of the code. Is an open() function defined somewhere? 
(which will "shadow" the built-in function)
That said the description doesn't quite match.
Please copy-paste the exact error messages because there's likely 
missing information...
-- 
Regards =dn


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /