¡@

Home 

python Programming Glossary: struct

What is a “callable” in Python?

http://stackoverflow.com/questions/111234/what-is-a-callable-in-python

method or is of a type that has a non null tp_call c struct member which indicates callability otherwise such as in functions..

How Do I Use Raw Socket in Python?

http://stackoverflow.com/questions/1117958/how-do-i-use-raw-socket-in-python

in semantics to UNIX's raw socket but without the struct s that define the packets structure. I was wondering if it would.. socket but without the struct s that define the packets structure. I was wondering if it would even be better not to write.. could have anything you want instead # Have a look at the 'struct' module for more # flexible packing unpacking of binary data..

How do I determine if my python shell is executing in 32bit or 64bit mode on OS X?

http://stackoverflow.com/questions/1405913/how-do-i-determine-if-my-python-shell-is-executing-in-32bit-or-64bit-mode-on-os

work on all Python 2 and 3 releases python 32 c 'import struct print 8 struct.calcsize P ' 32 python 64 c 'import struct print.. Python 2 and 3 releases python 32 c 'import struct print 8 struct.calcsize P ' 32 python 64 c 'import struct print 8 struct.calcsize.. struct print 8 struct.calcsize P ' 32 python 64 c 'import struct print 8 struct.calcsize P ' 64 BTW you might be tempted to use..

How do you convert a python time.struct_time object into a datetime object?

http://stackoverflow.com/questions/1697815/how-do-you-convert-a-python-time-struct-time-object-into-a-datetime-object

do you convert a python time.struct_time object into a datetime object How do you convert a python.. into a datetime object How do you convert a python time.struct_time object into a datetime.datetime object I have a library..

python: list vs tuple, when to use each?

http://stackoverflow.com/questions/1708510/python-list-vs-tuple-when-to-use-each

for heterogenous collections similar to what you'd use struct s for in C and lists being for homogenous collections similar..

What are “named tuples” in Python?

http://stackoverflow.com/questions/2970608/what-are-named-tuples-in-python

the standard tuple syntax. They can be used similarly to struct or other common record types except that they are immutable...

How are Python's Built In Dictionaries Implemented

http://stackoverflow.com/questions/327311/how-are-pythons-built-in-dictionaries-implemented

able to find any sort of definitive answer. python data structures dictionary implementation share improve this question.. of the three values . This is implemented as a C struct see dictobject.h 51 56 The figure below is a logical representation..

convert a string of bytes into an int (python)

http://stackoverflow.com/questions/444591/convert-a-string-of-bytes-into-an-int-python

Greg's method is faster from timeit import Timer Timer 'struct.unpack L y xcc xa6 xbb 0 ' 'import struct' .timeit 0.36242198944091797.. Timer Timer 'struct.unpack L y xcc xa6 xbb 0 ' 'import struct' .timeit 0.36242198944091797 Timer int 'y xcc xa6 xbb'.encode.. a module isn't necessarily cheap take a look Timer import struct nstruct.unpack L y xcc xa6 xbb 0 .timeit 0.98822188377380371..

Efficient way of parsing fixed width files in Python

http://stackoverflow.com/questions/4914008/efficient-way-of-parsing-fixed-width-files-in-python

share improve this question Using the standard library's struct module would be fairly easy as well as extremely fast since.. values for the number of characters in the field. import struct fieldwidths 2 10 24 # negative widths represent ignored padding.. abs fw 'x' if fw 0 else 's' for fw in fieldwidths fieldstruct struct.Struct fmtstring parse fieldstruct.unpack_from print..

How to get console window width in python

http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python

os.environ def ioctl_GWINSZ fd try import fcntl termios struct os cr struct.unpack 'hh' fcntl.ioctl fd termios.TIOCGWINSZ '1234'.. def ioctl_GWINSZ fd try import fcntl termios struct os cr struct.unpack 'hh' fcntl.ioctl fd termios.TIOCGWINSZ '1234' except..

Multicast in Python

http://stackoverflow.com/questions/603852/multicast-in-python

question This works for me Receive import socket import struct MCAST_GRP '224.1.1.1' MCAST_PORT 5007 sock socket.socket socket.AF_INET.. socket.SO_REUSEADDR 1 sock.bind '' MCAST_PORT mreq struct.pack 4sl socket.inet_aton MCAST_GRP socket.INADDR_ANY sock.setsockopt..

Creating a singleton in python

http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python

recipes 498149 which essentially recreates C style struct s in Python using metaclasses. The thread What are your concrete..

How can I check if an ip is in a network in python

http://stackoverflow.com/questions/819355/how-can-i-check-if-an-ip-is-in-a-network-in-python

This article shows you can do it with socket and struct modules without too much extra effort. I added a little to the.. I added a little to the article as follows import socket struct def makeMask n return a mask of n bits as a long integer return.. convert decimal dotted quad string to long integer return struct.unpack 'L' socket.inet_aton ip 0 def networkMask ip bits Convert..

Detect & Record Audio in Python

http://stackoverflow.com/questions/892199/detect-record-audio-in-python

from sys import byteorder from array import array from struct import pack import pyaudio import wave THRESHOLD 500 CHUNK_SIZE..

Is it preferable to return an anonymous class or an object to use as a 'struct'?

http://stackoverflow.com/questions/11577900/is-it-preferable-to-return-an-anonymous-class-or-an-object-to-use-as-a-struct

a dict subclass which I found here . It looks like class Struct dict Python Objects that act like Javascript Objects def __init__.. Javascript Objects def __init__ self args kwargs super Struct self .__init__ args kwargs self.__dict__ self This object can.. self.__dict__ self This object can be used this way o Struct x 10 o.y 20 o 'z' 30 print o.x o 'y' o.z The different types..

Python Class Factory to Produce simple Struct-like classes

http://stackoverflow.com/questions/1264833/python-class-factory-to-produce-simple-struct-like-classes

Class Factory to Produce simple Struct like classes While investigating Ruby I came across this to.. investigating Ruby I came across this to create a simple Struct like class Person Struct.new forname surname person1 Person.new.. across this to create a simple Struct like class Person Struct.new forname surname person1 Person.new 'John' 'Doe' puts person1..

Convert Python dict to object?

http://stackoverflow.com/questions/1305532/convert-python-dict-to-object

suits your needs from collections import namedtuple MyStruct namedtuple 'MyStruct' 'a b d' s MyStruct a 1 b 'c' 2 d 'hi'.. from collections import namedtuple MyStruct namedtuple 'MyStruct' 'a b d' s MyStruct a 1 b 'c' 2 d 'hi' s MyStruct a 1 b 'c'.. namedtuple MyStruct namedtuple 'MyStruct' 'a b d' s MyStruct a 1 b 'c' 2 d 'hi' s MyStruct a 1 b 'c' 2 d 'hi' s.a 1 s.b 'c'..

gdb-python : Parsing structure's each field and print them with proper value, if exists

http://stackoverflow.com/questions/16787289/gdb-python-parsing-structures-each-field-and-print-them-with-proper-value-if

before you should be able print its contents. Traversing a Struct While Following Pointers print struct follow pointers.py import.. ' s s s n' indent k v gdb.write ' s n' indent class PrintStructFollowPointers gdb.Command ''' print struct follow pointers LEVEL_LIMIT.. LEVEL_LIMIT STRUCT VALUE ''' def __init__ self super PrintStructFollowPointers self .__init__ 'print struct follow pointers'..

YAML parsing and Python?

http://stackoverflow.com/questions/6866600/yaml-parsing-and-python

and now you have to convert it to a Python object class Struct def __init__ self entries self.__dict__.update entries Then.. entries Then you can use args your YAML dictionary s Struct args s __main__.Struct instance at 0x01D6A738 s... and follow.. can use args your YAML dictionary s Struct args s __main__.Struct instance at 0x01D6A738 s... and follow Convert Python dict to..