python strings

?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

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

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

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.
s = "\x000"
s[0] == chr(0) True

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

iD8DBQFEWQjRdIO4ozGCH14RAsf4AJ4xdbT/FQTSzfciijgVBEfMyTH8SQCeJP39
xzJxWxlAnRgKimsKSKWhSQ0=
=Dd3B
-----END PGP SIGNATURE-----
 
B

Bryan

Gerhard said:
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.
s = "\x000"
s[0] == chr(0)
True

- -- Gerhard

this works too :)
>>> s = '\x001'
>>> s[0] == chr(0) True
>>> s = '\x00abc'
>>> s[0] == chr(0)
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.
>>> s = '\x00'
>>> s[0] == chr(0)
True


bryan
 

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,294
Messages
2,571,511
Members
48,207
Latest member
KazukoCape

Latest Threads

Top