Unable to strip \n characters

Peter Otten __peter__ at web.de
Sun May 20 07:19:30 EDT 2007


aiwarrior wrote:

> Im writing a personal wrapper to the perl script offered by
> rapidshare, so that im able to use multiple files and glob pathnames,
> but im using a file so i can track and resume any uploading data. The
> problem is the lines come with a \n character that im not bein able to
> take out,
> 
>         files = f.readlines()
>         for upload in files:

The readlines() is call is superfluous; just iterate over the file instead:

          for upload in f:

>                 upload.strip("\n")

Python strings are immutable (cannot be altered). Instead of changing them
you create a new one that you assign to the same name:

                  upload = upload.strip("\n")

Peter



More information about the Python-list mailing list