Problem Writing Files

Mark Nenadov mark at freelance-developer.com
Wed Apr 17 08:37:33 EDT 2002


Roger Jones wrote:

> I am using ActiveState Python 2.1 under Windows NT  and after opening a
> file with:
> 
> afile=('test.dat','w')
> afile.write('some random test text')
> afile.read()
> 
> It fills the file with many x's and 0's and also with various other
> text.
> How can this action be fixed so that it writes the text properly?
> 
> Thanks!
> 
> -Roger Jones
> 
> 

You are missing something in your first line. Instead of doing 
"afile=('test.dat', 'w')" you should do "afile=open('test.dat', 'w')".

The problem is that you are creating a tuple (with the elements 'test.dat' 
and 'w') instead of an actual file object.

-- 
-- Mark Nenadov (http://www.freelance-developer.com)



More information about the Python-list mailing list