FAQ
i get a string from a web server and i save it in to a file, that i
open the file and i read the string:
the string looks like :
http://lhti.gs/JKBTYD
after the read i use webbrowser open (sting), but i get the error
because at the end of the string are added '%0D%0A', and if i ask for
the len of the sting it include also the"'%0D%0A".
My question is how i can cut the last part of the string if it is
every time different?

Luca

Search Discussions

  • Alf P. Steinbach at Apr 22, 2010 at 12:35 pm

    * luca72:
    i get a string from a web server and i save it in to a file, that i
    open the file and i read the string:
    the string looks like :
    http://lhti.gs/JKBTYD
    after the read i use webbrowser open (sting), but i get the error
    because at the end of the string are added '%0D%0A', and if i ask for
    the len of the sting it include also the"'%0D%0A".
    My question is how i can cut the last part of the string if it is
    every time different?
    Try rtrim.

    Cheers & hth.,

    - Alf
  • Bruno Desthuilliers at Apr 22, 2010 at 1:04 pm

    luca72 a ?crit :
    i get a string from a web server and i save it in to a file, that i
    open the file and i read the string:
    the string looks like :
    http://lhti.gs/JKBTYD
    after the read i use webbrowser open (sting), but i get the error
    because at the end of the string are added '%0D%0A',
    Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
    [GCC 4.3.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import urllib
    urllib.unquote("%0D%0A")
    '\r\n'
    >>>

    Can't tell if this comes from the source ("i get a string from a web
    server") or if you (unwantingly) add it yourself when writing to or
    reading from the file.
    and if i ask for
    the len of the sting it include also the"'%0D%0A".
    My question is how i can cut the last part of the string if it is
    every time different?
    You'd be better fixing the problem where it happens. FWIW, str.strip()
    might help here.

    HTH

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedApr 22, '10 at 12:33p
activeApr 22, '10 at 1:04p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase