469,358 Members | 1,633 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

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

May 20 '07 #1
6 1781
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
May 20 '07 #2

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)

May 20 '07 #3

On May 20, 2007, at 7:41 AM, Michael Bentley wrote:
(upload.strip())
Oops: (upload.strip(),) or upload.strip()

May 20 '07 #4
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

May 21 '07 #5
On May 21, 7:05 am, Asun Friere <afri...@yahoo.co.ukwrote:
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?

May 21 '07 #6
On May 22, 6:37 am, aiwarrior <zube...@yahoo.com.brwrote:
On May 21, 7:05 am, Asun Friere <afri...@yahoo.co.ukwrote:
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).

May 23 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Giampiero Gabbiani | last post: by
3 posts views Thread by alex.mcshane | last post: by
5 posts views Thread by dan.j.weber | last post: by
4 posts views Thread by Steve | last post: by
6 posts views Thread by eight02645999 | last post: by
3 posts views Thread by Colin J. Williams | last post: by
6 posts views Thread by Christoph Zwerschke | last post: by
4 posts views Thread by Poppy | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.