Unable to strip \n characters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aiwarrior

    #1

    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_upl oad
    prem user password

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

  • Peter Otten

    #2
    Re: Unable to strip \n characters

    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

    Comment

    • Michael Bentley

      #3
      Re: Unable to strip \n characters


      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(fina l_args)

      Comment

      • Michael Bentley

        #4
        Re: Unable to strip \n characters


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

        Comment

        • Asun Friere

          #5
          Re: Unable to strip \n characters

          On May 20, 10:49 pm, Michael Bentley <mich...@jedimi ndworks.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

          Comment

          • aiwarrior

            #6
            Re: Unable to strip \n characters

            On May 21, 7:05 am, Asun Friere <afri...@yahoo. co.ukwrote:
            On May 20, 10:49 pm, Michael Bentley <mich...@jedimi ndworks.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?

            Comment

            • Asun Friere

              #7
              Re: Unable to strip \n characters

              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...@jedimi ndworks.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).

              Comment

              Working...