Difference between str and string

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

    Difference between str and string

    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.Stri ngIO(path)).get value())

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

    any suggestions would be most welcome...

    --
    Hugh Macdonald
  • Martin v. Löwis

    #2
    Re: Difference between str and string

    Hugh Macdonald wrote:
    [color=blue]
    > Anyway, any idea what I'm doing wrong or what python's doing wrong?[/color]

    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

    Comment

    Working...