reading files

Steve Holden steve at holdenweb.com
Mon Dec 19 05:30:32 EST 2005


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.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list