python strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike7411@gmail.com

    #1

    python strings

    Is it possible for python strings to contain a zero byte?

  • Grant Edwards

    #2
    Re: python strings

    On 2006-05-03, mike7411@gmail. com <mike7411@gmail .com> wrote:
    [color=blue]
    > Is it possible for python strings to contain a zero byte?[/color]

    Yes.

    --
    Grant Edwards grante Yow! Actually, what
    at I'd like is a little toy
    visi.com spaceship!!

    Comment

    • Gerhard Häring

      #3
      Re: python strings

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      mike7411@gmail. com wrote:[color=blue]
      > Is it possible for python strings to contain a zero byte?[/color]

      Yes. Here's how to produce one:

      gerhard@lara:~$ python
      Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
      [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
      Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
      >>> s = "\x000"
      >>> s[0] == chr(0)[/color][/color][/color]
      True[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      - -- Gerhard
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.1 (GNU/Linux)
      Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

      iD8DBQFEWQjRdIO 4ozGCH14RAsf4AJ 4xdbT/FQTSzfciijgVBEf MyTH8SQCeJP39
      xzJxWxlAnRgKims KSKWhSQ0=
      =Dd3B
      -----END PGP SIGNATURE-----

      Comment

      • Bryan

        #4
        Re: python strings

        Gerhard Häring wrote:[color=blue]
        > Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
        > [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
        > Type "help", "copyright" , "credits" or "license" for more information.[color=green][color=darkred]
        >>>> s = "\x000"
        >>>> s[0] == chr(0)[/color][/color]
        > True
        >
        > - -- Gerhard[/color]

        this works too :)
        [color=blue][color=green][color=darkred]
        >>> s = '\x001'
        >>> s[0] == chr(0)[/color][/color][/color]
        True[color=blue][color=green][color=darkred]
        >>> s = '\x00abc'
        >>> s[0] == chr(0)[/color][/color][/color]
        True


        i think it would be more clear not to use 3 digits for this example since \x
        only uses the next two numbers, not 3.
        [color=blue][color=green][color=darkred]
        >>> s = '\x00'
        >>> s[0] == chr(0)[/color][/color][/color]
        True


        bryan

        Comment

        • Sion Arrowsmith

          #5
          Re: python strings

          Bryan <belred@gmail.c om> wrote:[color=blue][color=green][color=darkred]
          > >>> s = '\x00'
          > >>> s[0] == chr(0)[/color][/color]
          >True[/color]

          That's a little excessive when:
          [color=blue][color=green][color=darkred]
          >>> s = '\0'
          >>> s[0] == chr(0)[/color][/color][/color]
          True

          Oh, and to reassure the OP that that null really is *in* the string:
          [color=blue][color=green][color=darkred]
          >>> len(s)[/color][/color][/color]
          1

          --
          \S -- siona@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
          ___ | "Frankly I have no feelings towards penguins one way or the other"
          \X/ | -- Arthur C. Clarke
          her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

          Comment

          Working...