strings

E

Egor Bolonev

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
 
B

Bengt Richter

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
Trick question ;-)
>>> pf = 'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
>>> pf[:pf.index('/x00')] 'Pink Floyd'
>>> list(pf)
['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
 
B

Bengt Richter

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).
Yes it's weird. The Interactive window of PythonWin shows it correct, but
debugger window is not.:-(
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
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top