Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Unable to strip \n characters

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


zubeido at yahoo

May 20, 2007, 3:50 AM

Post #1 of 7 (58 views)
Permalink
Unable to strip \n characters

Hi
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:
upload.strip("\n")
final_args = "./rsapiresume.pl %s prem user password"
% (upload)
print upload
#os.system( final_args )

My upload string still comes with the \n making the system call look
like this:

./rsapiresume.pl filename_to_upload
prem user password

I've already tried replace but it doesn't work either

--
http://mail.python.org/mailman/listinfo/python-list


__peter__ at web

May 20, 2007, 4:19 AM

Post #2 of 7 (54 views)
Permalink
Re: Unable to strip \n characters [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


michael at jedimindworks

May 20, 2007, 5:41 AM

Post #3 of 7 (54 views)
Permalink
Re: Unable to strip \n characters [In reply to]

On May 20, 2007, at 5:50 AM, aiwarrior wrote:

> files = f.readlines()
> for upload in files:
> upload.strip("\n")
> final_args = "./rsapiresume.pl %s prem user password" % (upload)
> print upload
> #os.system( final_args )

for upload in f:
final_args = "./rsapiresume.pl %s prem user password" %
(upload.strip())
print final_args
#os.system(final_args)

--
http://mail.python.org/mailman/listinfo/python-list


michael at jedimindworks

May 20, 2007, 5:49 AM

Post #4 of 7 (55 views)
Permalink
Re: Unable to strip \n characters [In reply to]

On May 20, 2007, at 7:41 AM, Michael Bentley wrote:

> (upload.strip())

Oops: (upload.strip(),) or upload.strip()

--
http://mail.python.org/mailman/listinfo/python-list


afriere at yahoo

May 20, 2007, 11:05 PM

Post #5 of 7 (48 views)
Permalink
Re: Unable to strip \n characters [In reply to]

On May 20, 10:49 pm, Michael Bentley <mich...@jedimindworks.com>
wrote:
> On May 20, 2007, at 7:41 AM, Michael Bentley wrote:
>
> > (upload.strip())
>
> Oops: (upload.strip(),) or upload.strip()

Superfluous though the braces around your original were, it should
still run ...
ie. (a) == a

--
http://mail.python.org/mailman/listinfo/python-list


zubeido at yahoo

May 21, 2007, 1:37 PM

Post #6 of 7 (47 views)
Permalink
Re: Unable to strip \n characters [In reply to]

On May 21, 7:05 am, Asun Friere <afri...@yahoo.co.uk> wrote:
> On May 20, 10:49 pm, Michael Bentley <mich...@jedimindworks.com>
> wrote:
>
> > On May 20, 2007, at 7:41 AM, Michael Bentley wrote:
>
> > > (upload.strip())
>
> > Oops: (upload.strip(),) or upload.strip()
>
> Superfluous though the braces around your original were, it should
> still run ...
> ie. (a) == a

When you mean superfluous you mean it makes a diffrence in run-time or
just code style?

--
http://mail.python.org/mailman/listinfo/python-list


afriere at yahoo

May 23, 2007, 12:23 AM

Post #7 of 7 (41 views)
Permalink
Re: Unable to strip \n characters [In reply to]

On May 22, 6:37 am, aiwarrior <zube...@yahoo.com.br> wrote:
> On May 21, 7:05 am, Asun Friere <afri...@yahoo.co.uk> wrote:
>
> > On May 20, 10:49 pm, Michael Bentley <mich...@jedimindworks.com>
> > wrote:
>
> > > On May 20, 2007, at 7:41 AM, Michael Bentley wrote:
>
> > > > (upload.strip())
>
> > > Oops: (upload.strip(),) or upload.strip()
>
> > Superfluous though the braces around your original were, it should
> > still run ...
> > ie. (a) == a
>
> When you mean superfluous you mean it makes a diffrence in run-time or
> just code style?


Hmm I thought I already answered, but it hasn't turned up so ...

It is superfluous in both senses, ie it will (v. marginally) affect
run-time performance, and it is generally considered good coding style
not to include parentheses where they are not needed, (though one
should not be absolute about this, there may be cases where
superfluous parentheses greatly clarify the meaning of some code).

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.