Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5707

Re: Python 3.x and bytes

Date 2011-05-18 09:40 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Re: Python 3.x and bytes
References <4DD2C2A5.3080403@stoneleaf.us> <BANLkTimvzZeN5dmm2xHP5xV8Kpw2Nb9kuQ@mail.gmail.com> <4DD2D89D.4000303@stoneleaf.us> <BANLkTintqgBLFtBx8+1b+R10nywuKdKHOw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1756.1305736108.9059.python-list@python.org> (permalink)

Show all headers | View raw


Ian Kelly wrote:
> On Tue, May 17, 2011 at 2:20 PM, Ethan Furman <ethan@stoneleaf.us> 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 object.  Passing it into the constructor is redundant.

However, as I just discovered, it works well when dealing with a 
bytearray object:

some_var = bytearray(b' ' * size) # want space initialized, not null

~Ethan~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python 3.x and bytes Ethan Furman <ethan@stoneleaf.us> - 2011-05-18 09:40 -0700

csiph-web