reading files

bonono at gmail.com bonono at gmail.com
Mon Dec 19 11:36:47 CET 2005


Steve Holden wrote:
> Johhny wrote:
> > Hello All,
> >
> > I am working my way through learning python as a language. I am having
> > some issues with something that looks right and does not work. I am
> > trying to get myself more familure with reading files. Based on the
> > tutorials at www.python.org This "should" work. but im not sure what
> > the issue is.
> >
> > ===SNIP===
> > import string
> >
> > vsftpd=open('vsftpd.conf', 'r')
> > print vsftpd
> > vsftpd.read()
> > vsftpd.readlines()
> >
> > vsftpd.close()
> > ===SNIP===
> >
> > When I check the permissions to ensure they are correct I get the
> > following.
> >
> > stat vsftpd.conf
> >   File: `vsftpd.conf'
> >   Size: 4137            Blocks: 16         IO Block: 131072 regular
> > file
> > Device: 802h/2050d      Inode: 51010       Links: 1
> > Access: (0644/-rw-r--r--)  Uid: ( 1000/  testing)   Gid: ( 1000/
> > testing)
> > Access: 2005-12-19 10:21:04.000000000 +0000
> > Modify: 2005-12-16 12:34:00.000000000 +0000
> > Change: 2005-12-16 12:34:00.000000000 +0000
> >
> > When I run the script I get the following:
> >
> > python reading_file.py
> > <open file 'vsftpd.conf', mode 'r' at 0xb7d742a8>
> >
> > Does anyone have any advice on this issue at all.
> >
> Yes: Python is doing exactly what you've told it to.
>
> vsftpd is a file object, and what you are seeing is the representation
> (repr()) of that object.
>
> Try
>
>    print vsftpd.read()
>
> instead and you'll see the content of the file.
> 
The obvious is not so obvious for this user.




More information about the Python-list mailing list