|
|
|
[Python] структуры данных
|
|||
|---|---|---|---|
|
#18+
Совсем перестал что-либо в Python(е) понимать: #у меня есть данные mydata = b'abcde' """ Хочу применить к ним что-то вроде typedef struct _mystruct{ BYTE a; WORD bc; WORD de; }*mystruct ; т.е. хочу наложить эту структуру на mydata: *mystruct = mydata и обращаться к полям этой структуры: mystruct.а - должно быть a """ как такое сделать? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.05.2010, 13:30:35 |
|
||
|
[Python] структуры данных
|
|||
|---|---|---|---|
|
#18+
http://docs.python.org/library/struct.html# ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.05.2010, 14:45:45 |
|
||
|
[Python] структуры данных
|
|||
|---|---|---|---|
|
#18+
belugin4http://docs.python.org/library/struct.html# Читал конечно же, но: struct.unpack(fmt, string) создаст мне (кортеж) новый объект! т.е. данные будут скопированы (фиг с ним, компьютеры быстрые, памяти много) кортеж , который будет создан не имеет имен данных !!! mydata = b'abcde' mystruct = struct.unpack('cii', mydata) print mystruct[0] #ЭТО какая-то фигня!!! хочу: mystruct.a ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.05.2010, 15:27:19 |
|
||
|
[Python] структуры данных
|
|||
|---|---|---|---|
|
#18+
http://docs.python.org/release/3.0/library/struct.html Unpacked fields can be named by assigning them to variables or by wrapping the result in a named tuple: >>> record = b'raymond \x32\x12\x08\x01\x08' >>> name, serialnum, school, gradelevel = unpack('<10sHHb', record) >>> from collections import namedtuple >>> Student = namedtuple('Student', 'name serialnum school gradelevel') >>> Student._make(unpack('<10sHHb', record)) Student(name=b'raymond ', serialnum=4658, school=264, gradelevel=8) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.05.2010, 17:15:40 |
|
||
|
|

start [/forum/topic.php?fid=16&msg=36615128&tid=1343700]: |
0ms |
get settings: |
7ms |
get forum list: |
13ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
21ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
52ms |
get tp. blocked users: |
1ms |
| others: | 191ms |
| total: | 301ms |

| 0 / 0 |
