I am trying to figure out how to rewrite the following chunk of code
in Python:
C source -
typedef struct PF
-
{
-
int flags;
-
long user;
-
char*filename;
-
unsigned char buffer[MAXBUFFERSIZE];
-
} PF;
-
-
typedef BLOCK
-
{
-
PF * packdata;
-
} BLOCK;
-
-
BLOCK* blocks;
-
My first idea was to create a class for PF and a class for BLOCK, but
I got lost somewhere along the lines. :\
Python Attempt: Please note that since I can't type TABs online
easily, I am using the @ character to represent TABs in the following
Python code. -
class PF:
-
@def __init__(self):
-
@@self.flags, self.user = 0, 0
-
@@self.filename = ''
-
@@self.buffer = []
-
-
class BLOCK:
-
@def __init__(self):
-
@@self.packdata = []
-
-
blocks = []
-
Any Python Gurus out there that can help me? 4 1383
On Fri, 06 Jul 2007 17:31:50 +0000, DeveloperX wrote:
I am trying to figure out how to rewrite the following chunk of code
in Python:
C source -
typedef struct PF
-
{
-
int flags;
-
long user;
-
char*filename;
-
unsigned char buffer[MAXBUFFERSIZE];
-
} PF;
-
typedef BLOCK
-
{
-
PF * packdata;
-
} BLOCK;
-
BLOCK* blocks;
-
My first idea was to create a class for PF and a class for BLOCK, but
I got lost somewhere along the lines. :\
Python Attempt: Please note that since I can't type TABs online
easily, I am using the @ character to represent TABs in the following
Python code. -
class PF:
-
@def __init__(self):
-
@@self.flags, self.user = 0, 0
-
@@self.filename = ''
-
@@self.buffer = []
-
class BLOCK:
-
@def __init__(self):
-
@@self.packdata = []
-
blocks = []
-
Any Python Gurus out there that can help me?
At a first glance it looks okay but unless we know what you are going to
do with these data structures it's hard to tell if it is really the best
"translation".
`PF.buffer` might be better a string or an `array.array`. And is `BLOCK`
really just a structure with *one* member? Looks a bit odd IMHO.
Ciao,
Marc 'BlackJack' Rintsch
On Fri, 06 Jul 2007 17:31:50 +0000, DeveloperX wrote:
Python Attempt: Please note that since I can't type TABs online
easily, I am using the @ character to represent TABs in the following
Python code.
Why not indent with spaces, just like you did for the example C code?
--
Steven.
Marc 'BlackJack' Rintsch a écrit :
On Fri, 06 Jul 2007 17:31:50 +0000, DeveloperX wrote:
>I am trying to figure out how to rewrite the following chunk of code in Python:
C source - typedef struct PF
- {
- int flags;
- long user;
- char*filename;
- unsigned char buffer[MAXBUFFERSIZE];
- } PF;
- typedef BLOCK
- {
- PF * packdata;
- } BLOCK;
- BLOCK* blocks;
My first idea was to create a class for PF and a class for BLOCK, but I got lost somewhere along the lines. :\
Python Attempt: Please note that since I can't type TABs online easily, I am using the @ character to represent TABs in the following Python code. - class PF:
- @def __init__(self):
- @@self.flags, self.user = 0, 0
- @@self.filename = ''
- @@self.buffer = []
- class BLOCK:
- @def __init__(self):
- @@self.packdata = []
- blocks = []
Any Python Gurus out there that can help me?
At a first glance it looks okay but unless we know what you are going to
do with these data structures it's hard to tell if it is really the best
"translation".
`PF.buffer` might be better a string
Mmm... We can't tell for sure since we have no use case, but I'm not
sure that the OP wants an immutable object here.
or an `array.array`.
or a StringIO.
And is `BLOCK`
really just a structure with *one* member? Looks a bit odd IMHO.
+1
<OP>
Unless you have behaviours attached to this type, you may as well just
use lists.
</OP>
And while we're at it, Python's conventions are that ALL_UPPER names
denotes (pseudo) constants. For types, the conventions is to use
CantRememberIfItsCamelOrMixedCaseButYouShouldGetTh eIdeaByNow.
HTH
On Jul 10, 5:05 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
Mmm... We can't tell for sure since we have no use case, but I'm not
sure that the OP wants an immutable object here.
or an `array.array`.
or a StringIO.
And is `BLOCK`
really just a structure with *one* member? Looks a bit odd IMHO.
+1
<OP>
Unless you have behaviours attached to this type, you may as well just
use lists.
</OP>
And while we're at it, Python's conventions are that ALL_UPPER names
denotes (pseudo) constants. For types, the conventions is to use
CantRememberIfItsCamelOrMixedCaseButYouShouldGetTh eIdeaByNow.
HTH
I just used the same convention that the C code used in this post.
I write my python classes and functions in CamelCaps.
Not completely certain what to do at this point. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: MiLF |
last post by:
Is it possible to write a Audio CD Player by using python only?
|
by: John Ladasky |
last post by:
Hi, folks,
At the beginning of 2003, I was a frustrated computer user, and lapsed
programmer, with problems to solve that screamed for programming.
Thanks to the Python language and community, I...
|
by: AMD |
last post by:
Hi,
I need to write a Win32 DLL and I would like to use Python instead of
VB, C++ or Delphi. Is this possible?
Thank you,
Andre M. Descombes
|
by: Nick Evans |
last post by:
Hello there,
I have been on and off learning to code (with python being the second
language I have worked on after a bit of BASIC). What I really want to know
is, if you are going to actually...
|
by: Levi Campbell |
last post by:
Hi, I'm thinking about writing a system for DJing in python, but I'm
not sure if Python is fast enough to handle the realtime audio needed
for DJing, could a guru shed some light on this subject...
|
by: Raj |
last post by:
Hi,
We just executed a project with Python using TG. The feedback was to
use more python like programming rather than C style code executed in
Python. The feedback is from a Python purist and...
|
by: Matthew Warren |
last post by:
I have the following piece of code, taken from a bigger module, that
even as I was writing I _knew_ there were better ways of doing it, using
a parser or somesuch at least, but learning how wasn't...
|
by: dmoore |
last post by:
Hi folks,
I've seen the following issue come up in multiple posts to this
mailing list:
I have a python program that spawns a child process with popen or
popen2 or popen3 or popen2.popen2...
|
by: madsornomads |
last post by:
Hi all,
I have a problem with reading from a Java server after I have written
to it - it just hangs. It works fine if I just write to the server and
not try to write. I have read the HOWTO on...
|
by: duli |
last post by:
Hi:
I would like recommendations for books (in any language, not
necessarily C++, C, python) which have walkthroughs for developing
a big software project ? So starting from inception, problem...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |