strings

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

    strings

    Hi All!

    I have a
    'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    and I want a
    'Pink Floyd'
    How can I manage it?

    This one isn't work.
    author=f.read(3 0).replace('\0' ,' ').rstrip() #from mp3 tag


    --
    Egor [ru eo en]


  • Bengt Richter

    #2
    Re: strings

    On Mon, 30 Jun 2003 09:54:24 +1100, "Egor Bolonev" <ebolonev@mail. ru> wrote:
    [color=blue]
    >Hi All!
    >
    >I have a
    >'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    >and I want a
    >'Pink Floyd'
    >How can I manage it?
    >
    >This one isn't work.
    >author=f.read( 30).replace('\0 ',' ').rstrip() #from mp3 tag
    >[/color]
    Trick question ;-)
    [color=blue][color=green][color=darkred]
    >>> pf = 'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    >>> pf[:pf.index('/x00')][/color][/color][/color]
    'Pink Floyd'[color=blue][color=green][color=darkred]
    >>> list(pf)[/color][/color][/color]
    ['P', 'i', 'n', 'k', ' ', 'F', 'l', 'o', 'y', 'd', '/', 'x', '0', '0', '/', 'x', '0', '0', '/',
    'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '
    /', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0
    ']

    I.e., '/x00' is not '\x00' ;-)

    Regards,
    Bengt Richter

    Comment

    • Bengt Richter

      #3
      Re: strings

      On Mon, 30 Jun 2003 10:27:52 +1100, "Egor Bolonev" <ebolonev@mail. ru> wrote:
      [color=blue][color=green][color=darkred]
      >> > Hi All!
      >> >
      >> > I have a
      >> > 'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
      >> > and I want a
      >> > 'Pink Floyd'
      >> > How can I manage it?
      >> >
      >> > This one isn't work.
      >> > author=f.read(3 0).replace('\0' ,' ').rstrip() #from mp3 tag[/color][/color][/color]
      If you are playing around with various methods, don't forget
      to f.seek(0) between (assuming what you have is at the beginning of the file).
      [color=blue][color=green][color=darkred]
      >> >[/color]
      >>
      >> That is weird. Are you sure? It works on my system:
      >> (BTW: I think you mean \x00 instead of /x00)
      >>[color=darkred]
      >> >>> a='Pink Floyd\x00\x00\x 00\x00\x00\x00\ x00\x00\x00\x00 \x00\x00'
      >> >>> a[/color]
      >> 'Pink Floyd\x00\x00\x 00\x00\x00\x00\ x00\x00\x00\x00 \x00\x00'[color=darkred]
      >> >>> a.replace('\0', ' ').rstrip()[/color]
      >> 'Pink Floyd'[color=darkred]
      >> >>>[/color][/color]
      >
      >Yes it's weird. The Interactive window of PythonWin shows it correct, but
      >debugger window is not.:-([/color]
      Did you try it with a fixed string like a above?

      BTW, a.replace('\0', '') should work without creating and then stripping spaces, I think.
      also a.rstrip('\0') -- though the meanings of all these are different if \x00 occurs internally,
      not just in the tail.

      Regards,
      Bengt Richter

      Comment

      Working...