|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
Python3 bytearray padding
Hi, I'm trying to create a padded bytearray in Python3. Currently I have something like this: Code:
inputstuff = [
('A' , b'ABCD'),
('B' , b'EFGH'),
('C' , b'IJKL'),
('D' , b'MNOP')
]
BA = bytearray()
for thing in inputstuff:
BA.extend(thing[1])
print(BA.decode('latin1'))
print(BA)
for thing in BA:
print(thing)This works and gives output like this: Code:
ABCDEFGHIJKLMNOP bytearray(b'ABCDEFGHIJKLMNOP') 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 Which is expected. However, what i'd actually like to do is pad the bytes I add to the bytearray with blanks such that it would be more like this: ABCD EFGH IJKL MNOP Obviously I could just add spaces to the end of each string defined as A, B, C and D - but i'd rather not do that as it would get complicated when I use this code in a real scenario where these are objects being passed into the function etc. If anybody knows how to do this i'd be very grateful of your help. Regards, Phil Last edited by pludi; 4 Weeks Ago at 08:16 AM.. Reason: code tags, please... |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Padding with zeros. | sbasetty | Shell Programming and Scripting | 10 | 05-18-2009 07:09 PM |
| How to convert byteArray variables to HexaString variables for Linux? | ritesh_163 | Programming | 2 | 08-10-2008 11:55 PM |
| Padding in Unix | rudoraj | Shell Programming and Scripting | 3 | 02-20-2008 11:06 PM |
| Padding | vijaygopalsk | UNIX for Dummies Questions & Answers | 2 | 06-27-2003 10:51 AM |
| Padding issues | informshilpa | UNIX for Advanced & Expert Users | 2 | 03-01-2002 12:51 PM |