Re: Python 3.x and bytes

2011-05-18 Thread Ethan Furman
Ian Kelly wrote: On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: The big question, though, is would you do it this way: some_var = bytes(23).replace(b'\x00', b'a') or this way? some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var = b'a' * 23 That's already a b

Re: Python 3.x and bytes

2011-05-17 Thread Terry Reedy
On 5/17/2011 5:27 PM, Corey Richardson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/17/2011 04:55 PM, Ethan Furman wrote: Apparently, it's not well documented. If you check PEP 358 you'll find it. ~Ethan~ Agreed, it looks like it should be mentioned in bytes.__doc__ about the

Re: Python 3.x and bytes

2011-05-17 Thread Terry Reedy
On 5/17/2011 3:39 PM, MRAB wrote: On 17/05/2011 19:47, Ethan Furman wrote: In Python 3 one can say --> huh = bytes(5) BTW, help(bytes) doesn't seem to mention it! I believe I mentioned that on some tracker issue. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.x and bytes

2011-05-17 Thread Ethan Furman
Ian Kelly wrote: On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: The big question, though, is would you do it this way: some_var = bytes(23).replace(b'\x00', b'a') or this way? some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var = b'a' * 23 That's already a b

Re: Python 3.x and bytes

2011-05-17 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/17/2011 04:55 PM, Ethan Furman wrote: > Apparently, it's not well documented. If you check PEP 358 > you'll find it. > > ~Ethan~ Agreed, it looks like it should be mentioned in bytes.__doc__ about the single-integer argument. - -- Corey Ric

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: > The big question, though, is would you do it this way: > > some_var = bytes(23).replace(b'\x00', b'a') > > or this way? > > some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var = b'a' * 23 That's already a bytes objec

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 1:50 PM, Corey Richardson wrote: > - From help(bytes): >  |  bytes(iterable_of_ints) -> bytes >  |  bytes(string, encoding[, errors]) -> bytes >  |  bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer >  |  bytes(memory_view) -> bytes > > Looks like you're using the

Re: Python 3.x and bytes

2011-05-17 Thread Felipe Bastos Nunes
Mine bytes constructor when useing Corey's advice give's me a string instead of a b''... 2011/5/17 Corey Richardson > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 05/17/2011 02:47 PM, Ethan Furman wrote: > > In Python 3 one can say > > > > --> huh = bytes(5) > > > > Since the bytes typ

Re: Python 3.x and bytes

2011-05-17 Thread Ethan Furman
Corey Richardson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/17/2011 02:47 PM, Ethan Furman wrote: In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the

Re: Python 3.x and bytes

2011-05-17 Thread Felipe Bastos Nunes
This piece of code works fine for me: > >>> somevar = bytes() > >>> somevar > '' > >>> somevar.replace(b'', b'10') > '10' > >>> somevar > '' > >>> somevar = somevar.replace(b'', b'10') > >>> somevar > '10' > >>> somevar2 = bytes(b'10'*2) > >>> somevar2 > '1010' > >>> somevar2 = somevar2.replace(b'

Re: Python 3.x and bytes

2011-05-17 Thread Ethan Furman
Felipe Bastos Nunes wrote: 2011/5/17 Ethan Furman wrote: In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: --> huh b'\x00

Re: Python 3.x and bytes

2011-05-17 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/17/2011 02:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have > expected this to have huh being a bytestring with one element -- the > integer 5.

Re: Python 3.x and bytes

2011-05-17 Thread MRAB
On 17/05/2011 19:47, Ethan Furman wrote: In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: --> huh b'\x00\x00\x00\x00\x00' or f

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 1:20 PM, Ian Kelly wrote: > I suppose it's for interoperability with the mutable bytearray type, > which takes the same parameters in the constructor. http://www.python.org/dev/peps/pep-3137/#constructors -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.x and bytes

2011-05-17 Thread Felipe Bastos Nunes
They accept .replace(b"00", b"12") for example. Documentation about it. 2011/5/17 Ethan Furman > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this t

Re: Python 3.x and bytes

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 12:47 PM, Ethan Furman wrote: > In Python 3 one can say > > --> huh = bytes(5) > > Since the bytes type is actually a list of integers, I would have expected > this to have huh being a bytestring with one element -- the integer 5. >  Actually, what you get is: > > --> huh >

Python 3.x and bytes

2011-05-17 Thread Ethan Furman
In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: --> huh b'\x00\x00\x00\x00\x00' or five null bytes. Note that this is an