Hi,
This is something I thought was a bit strange. It's really quite trivial, but just the same, I'm curious if anybody knows why this is happening.
I run the following script referencing the file 'newtext.txt' and an exception is raised:
class myfile:
def __init__(self, file):
self.myout=open(file,"w"
def writetext(self, text):
self.text=text
self.myout.write(self.text)
def __del__(self):
self.myout.close
x=myfile("C:\My Documents\My Python Scripts\newtext.txt"
x.writetext("This is the dawning of the age of Aquarius\n"
x=None
The following is the exception message:
Traceback (most recent call last):
File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\My Python Scripts\myout.py", line 12, in ?
x=myfile("C:\My Documents\My Python Scripts\newtext.txt"
File "C:\My Documents\My Python Scripts\myout.py", line 3, in __init__
self.myout=open(file,"w"
IOError: [Errno 2] No such file or directory: 'C:\\My Documents\\My Python Scripts\newtext.txt'
>>> Exception exceptions.AttributeError: "myfile instance has no attribute 'myout'" in <bound method myfile.__del__ of <__main__.myfile instance at 0x00F3D4B0>> ignored
The strange thing is, all I have to do is to change the name newtext.txt to anything else, eg: 'mytext.txt', 'dewtext.txt', etc., and it will work. (BTW, that's the only change I made.) I did a 'find' and there is definitely no file called 'newtext.txt' anywhere on my pc.
I am new to Python, but this seems goofy and rather arbitrary to me. Does anybody care to speculate why this might happen?
Thanks,
Grant.
This is something I thought was a bit strange. It's really quite trivial, but just the same, I'm curious if anybody knows why this is happening.
I run the following script referencing the file 'newtext.txt' and an exception is raised:
class myfile:
def __init__(self, file):
self.myout=open(file,"w"
def writetext(self, text):
self.text=text
self.myout.write(self.text)
def __del__(self):
self.myout.close
x=myfile("C:\My Documents\My Python Scripts\newtext.txt"
x.writetext("This is the dawning of the age of Aquarius\n"
x=None
The following is the exception message:
Traceback (most recent call last):
File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\My Python Scripts\myout.py", line 12, in ?
x=myfile("C:\My Documents\My Python Scripts\newtext.txt"
File "C:\My Documents\My Python Scripts\myout.py", line 3, in __init__
self.myout=open(file,"w"
IOError: [Errno 2] No such file or directory: 'C:\\My Documents\\My Python Scripts\newtext.txt'
>>> Exception exceptions.AttributeError: "myfile instance has no attribute 'myout'" in <bound method myfile.__del__ of <__main__.myfile instance at 0x00F3D4B0>> ignored
The strange thing is, all I have to do is to change the name newtext.txt to anything else, eg: 'mytext.txt', 'dewtext.txt', etc., and it will work. (BTW, that's the only change I made.) I did a 'find' and there is definitely no file called 'newtext.txt' anywhere on my pc.
I am new to Python, but this seems goofy and rather arbitrary to me. Does anybody care to speculate why this might happen?
Thanks,
Grant.