Unix fold command in python

D

dean

Hello Group:

Hopefully someone can answer my question.

I have a unix shell command that I would like to emulate in python.
The command is FOLD. I am scanning a file that contains a stream of
data with a record size of 242 bytes but no record delimiters. There
are multiple fields in each record that can be mapped according to
their position:

example

field1 byte 0-4
field2 byte 5-8
....
....
....
fieldn byte 238-242


How do I make python read a record in and report the contents of a
particular field (and may be carry out an operations with that field).

Much appreciated

regards
dean
 
I

Ivan Voras

dean said:
Hello Group:

Hopefully someone can answer my question.

I have a unix shell command that I would like to emulate in python.
The command is FOLD. I am scanning a file that contains a stream of
data with a record size of 242 bytes but no record delimiters. There

Have you looked at the 'struct' module?
 
K

Kannan Vijayan

Hello Group:

Hopefully someone can answer my question.

I have a unix shell command that I would like to emulate in python.
The command is FOLD. I am scanning a file that contains a stream of
data with a record size of 242 bytes but no record delimiters. There
are multiple fields in each record that can be mapped according to
their position:

example

field1 byte 0-4
field2 byte 5-8
...
...
...
fieldn byte 238-242


How do I make python read a record in and report the contents of a
particular field (and may be carry out an operations with that field).

Much appreciated

regards
dean

Is the data in some packed binary format? It seems from your
description that this is the case. I would consider looking at the
struct module. Read the docs on it to find out specifics of usage.

-kannan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top