[Tutor] Re: Files and such

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Sep 30 21:39:19 CEST 2004



On Thu, 30 Sep 2004, Danny Yoo wrote:

> When you're reading lines back from a file, all that Python knows is that
> the file contains a bunch of string lines.  For example:
>
> ###
> [dyoo at shoebox dyoo]$ cat >somenumbers
> 3
> 2
> 1
> [dyoo at shoebox dyoo]$ python
> Python 2.3.3 (#1, Aug  9 2004, 10:11:39)
> [GCC 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)] on
> linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>>
> >>>
> >>> lines = myfile.readlines()
> >>> lines
> ['3\n', '2\n', '1\n']


Gah!  *grin*


There's a missing line there, right before the readlines() statement:

###
>>> myfile = open('somenumbers')
###

Sorry about that!  I made a mistake when I copied/pasted the output from
my window.



More information about the Tutor mailing list