[Tutor] Need some help on output
Becky Mcquilling
ladymcse2000 at gmail.com
Fri Mar 4 08:47:22 CET 2011
Thanks, that helped. I took a second look and realized where I had tried
calling the .strip() method was wrong. Appreciate the pointer.
Becky
On Thu, Mar 3, 2011 at 5:37 PM, Kushal Kumaran <
kushal.kumaran+python at gmail.com> wrote:
> On Fri, Mar 4, 2011 at 6:48 AM, Becky Mcquilling <ladymcse2000 at gmail.com>
> wrote:
> > I am creating a dictionary by parsing a text file.
> >
> > The code is below:
> > backup_servers = {}
> > fo = open('c:/test/backup_shares.txt')
> > for line in fo:
> > backup_server = line.split(',')
> > backup_servers[backup_server[0]]=backup_server[1]
>
> Looping over a file object returns lines including the trailing
> newline. If that's not required, you have to remove the newline at
> the end yourself using the strip method.
>
> To see the behaviour, print out the value of line at the start of the loop
> body.
>
> Documentation on file objects:
> http://docs.python.org/library/stdtypes.html#file-objects
> Documentation on strings:
> http://docs.python.org/library/stdtypes.html#string-methods
>
> > <snip>
>
> --
> regards,
> kushal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110303/5177c674/attachment-0001.html>
More information about the Tutor
mailing list