Difference between str and string

H

Hugh Macdonald

I've been seeing some somewhat strange behaviour in a python script
that I'm writing and was wondering whether someone could help me out
here....

I have the following code:

path = getPath(bundle, item)
path = hub.parseString(path)

getPath is a function that returns a string, and hub.parseString is an
external C++ function that also returns a string..

When I run this at the moment, it gives:

TypeError: argument 1 must be string without null bytes, not str

However, if I add a print statement somewhere else in the code
completely (after this is executed, and printing out a different
variable altogether) it works (but only with some - it would only work
if I had both of the lines:

print "Details:"
print details

but it wouldn't work with just one...)


Anyway, any idea what I'm doing wrong or what python's doing wrong?

For the moment, I've got around this by doing:

path = hub.parseString((StringIO.StringIO(path)).getvalue())

Which works, but I don't like doing it...

any suggestions would be most welcome...
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Hugh said:
Anyway, any idea what I'm doing wrong or what python's doing wrong?

It looks you have a string with embedded null bytes, which is not
supported where you want to use it. Do

print repr(path)

to find out what precisely the value of path is (doing a plain print
would send the null bytes to the terminal, which might ignore them)

HTH,
Martin
 

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
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top