By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,714 Members | 750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,714 IT Pros & Developers. It's quick & easy.

Unable to strip \n characters

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a

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

P: n/a

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

May 20 '07 #4

P: n/a
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

P: n/a
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

P: n/a
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.