473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does Python provide "Struct" data structure?

Hello all:

I have found a useful module in IPython, named 'from IPython.ipstruct
import Struct".

So I can use it as follows:

####################################
from IPython.ipstruct import Struct

mystruct = Struct(echo = 1,
verb = 'Verbose',
filedir = 'C:/temp',
)

print mystruct.filedir
#####################################

I have two following questions:

1Does Python provide such Struct in this standard libary.
Python has "4.3 struct -- Interpret strings as packed binary data", but
it looks like different
from what I really want to get.

2Is it safe to use IPython's modules in my python program?
I will pack all my code into an executable application by using py2exe.
The clients would like to use this application without any python
intallation.
What should I pay attention if I include the IPython modules into my
python code and
convert it into executable application by using py2exe?

The setup.py for my application is as follows:
###########################################
from distutils.core import setup
import py2exe

options = {
"bundle_files": 1,
# "ascii": 1, # to make a smaller executable, don't include the
encodings
"compressed": 1, # compress the library archive
}

setup(
# The first three parameters are not required, if at least a
# 'version' is given, then a versioninfo resource is built from
# them and added to the executables.
version = "1.0",
description = "mycode",
name = "mycode",

options = {"py2exe": options},
zipfile = None, # append zip-archive to the executable.

# targets to build
console=['mycode.py'],
)
################################################## #

Does I need to make any modification if I include IPython module in my
code?

Thank you for your helps
-Daniel

Sep 22 '06 #1
4 4400
Daniel Mark wrote:
I have found a useful module in IPython, named 'from IPython.ipstruct
import Struct".
So I can use it as follows:
####################################
from IPython.ipstruct import Struct

mystruct = Struct(echo = 1,
verb = 'Verbose',
filedir = 'C:/temp',
)

print mystruct.filedir
#####################################
Does 'Bunch' fit the bill?
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52308

....
jay graves

Sep 22 '06 #2
Daniel Mark wrote:
I have two following questions:

1Does Python provide such Struct in this standard libary.
Python has "4.3 struct -- Interpret strings as packed binary
data", but it looks like different from what I really want to get.
Yes, that module is used when you want to deal with C structs in
binary form (e.g. useful at networking with binary protocols).

Try using dictionaries or custom, field-only class instances
as "struct".

Regards,
Björn

--
BOFH excuse #374:

It's the InterNIC's fault.

Sep 22 '06 #3
Hi Daniel,

To avoid problems you could vendor the ipython file you require, but an
easier solution may just be to implement your own version of the class
(it's extreemly easy):

class struct():
def __init__(self, *args, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)

mystruct = struct(echo = 1,
verb = 'Verbose',
filedir = 'C:/temp')

print mystruct.filedir

Regards,
Jordan

Sep 22 '06 #4
Daniel Mark wrote:
>
1Does Python provide such Struct in this standard libary.
Python has "4.3 struct -- Interpret strings as packed binary data", but
it looks like different
from what I really want to get.
I like the following version:

class Struct(dict):

def __getattr__(self,name):

try:
val=self[name]
except KeyError:
val=super(Struct,self).getattr(self,name)

return val

def __setattr__(self,name,val):

l=dir(self)

if name in self:
super(Struct,self).setattr(self,name,val)
else:
self[name]=val
it has the added benefit of having all of the dict methods too.
bb

--
-----------------

bb****@bryant.edu
http://web.bryant.edu/~bblais
Sep 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7551
by: R. Rajesh Jeba Anbiah | last post by:
Recently I've done a project to fiddle WAV (format) files. To read the headers, I've used something like: fseek($fp, 40); //Data length is at offset 40 $data_len = fread($fp, 4); //4 bytes ...
3
14476
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
14
3261
by: Steve Teeples | last post by:
I don't understand why I cannot use a property to modify data within a struct. Can someone tell me why I get the error "Cannot modify the return value of "myData.TheData" because it is not a...
10
2706
by: Pantokrator | last post by:
Hi, Is there any way to "overload" a struct? e.g. having already struct stA1 { int i_ID; int i_Type; };
4
5052
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
3
4328
by: angshuman.agarwal | last post by:
Structure in C DLL ---------------------------- typedef struct IrData { unsigned short uiFormat; unsigned short uiLength; unsigned char* pchData; } tagIrData; Function in C DLL
8
28427
by: Mohammad Omer Nasir | last post by:
Hi, i made a structure in header file "commonstructs.h" is: typedef struct A { int i; A( ) {
8
40447
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am...
20
1819
by: Francine.Neary | last post by:
People seem to have different views as to where the C reserved word "struct" comes from. One explanation is that it is a shortening of "structure", and another is that it is an acronym for "single...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.