Unable to strip \n characters

A

aiwarrior

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
 
P

Peter Otten

aiwarrior said:
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
 
M

Michael Bentley

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)
 
A

aiwarrior

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?
 
A

Asun Friere

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top