Re: Reading binary data with the CSV module

2020-11-30 Thread MRAB
On 2020-11-30 03:59, Jason Friedman wrote: csv.DictReader appears to be happy with a list of strings representing the lines. Try this: contents = source_file.content() for row in csv.DictReader(contents.decode('utf-8').splitlines()): print(row) Works great, thank you! Question ... wil

Re: Reading binary data with the CSV module

2020-11-29 Thread Jason Friedman
> > csv.DictReader appears to be happy with a list of strings representing > the lines. > > Try this: > > contents = source_file.content() > > for row in csv.DictReader(contents.decode('utf-8').splitlines()): > print(row) > Works great, thank you! Question ... will this form potentially use l

Re: Reading binary data with the CSV module

2020-11-29 Thread MRAB
On 2020-11-30 01:31, Jason Friedman wrote: Using the Box API: print(source_file.content()) returns b'First Name,Last Name,Email Address,Company,Position,Connected On\nPeter,van (and more data, not pasted here) Trying to read it via: with io.TextIOWrapper(source_file.content(), encoding=

Reading binary data with the CSV module

2020-11-29 Thread Jason Friedman
Using the Box API: print(source_file.content()) returns b'First Name,Last Name,Email Address,Company,Position,Connected On\nPeter,van (and more data, not pasted here) Trying to read it via: with io.TextIOWrapper(source_file.content(), encoding='utf-8') as text_file: reader = csv.DictRead

psycopg2 insertion and reading binary data to PostgreSQL database (bytea datatype)

2011-03-01 Thread romap
Hello. This is the full work version. Do yuo have: - Pyton, PostgreSQL, Psycopg2 - PostgreSQL dababase named "MyDATABASE" with table named "phonebook" - Table "phonebook" have this columns: "lastname" [TEXT datatype] and "c2image" [BYTEA datatype] - Do you have an jpeg file named "sun.jpg" on c:/

Re: reading binary data from a 32 bit machine on 64 bit machine

2009-02-19 Thread Gabriel Genellina
En Thu, 19 Feb 2009 16:51:39 -0200, harijay escribió: Hi I am very confused with the use of the struct module to read binary data from a file. ( I have only worked with ascii files so far) I have a file spec for a Data-logger (http://www.dataq.com/support/ techinfo/ff.htm) That format is rat

Re: reading binary data from a 32 bit machine on 64 bit machine

2009-02-19 Thread MRAB
harijay wrote: Hi I am very confused with the use of the struct module to read binary data from a file. ( I have only worked with ascii files so far) I have a file spec for a Data-logger (http://www.dataq.com/support/ techinfo/ff.htm) I am collecting some voltage , time traces on one channel an

reading binary data from a 32 bit machine on 64 bit machine

2009-02-19 Thread harijay
Hi I am very confused with the use of the struct module to read binary data from a file. ( I have only worked with ascii files so far) I have a file spec for a Data-logger (http://www.dataq.com/support/ techinfo/ff.htm) I am collecting some voltage , time traces on one channel and they are writte

Re: Reading binary data

2008-09-10 Thread Terry Reedy
Aaron Scott wrote: Taking everything into consideration, my code is now: import struct file = open("test.gde", "rb") signature = file.read(3) version, attr_count = struct.unpack('II', file.read(8)) print signature, version, attr_count for idx in xrange(attr_count): attr_id, attr_val_le

Re: Reading binary data

2008-09-10 Thread John Machin
On Sep 11, 4:16 am, Aaron Scott <[EMAIL PROTECTED]> wrote: > Taking everything into consideration, my code is now: > > import struct > file = open("test.gde", "rb") > signature = file.read(3) > version, attr_count = struct.unpack('II', file.read(8)) > print signature, version, attr_count > for idx

Re: Reading binary data

2008-09-10 Thread nntpman68
What I would do first is to print the result byte by byte each as hexadecimal number. If you can I would additionally populate the C-structure with numbers, which are easier to follow. Example: signature = "ABC" // same as 0x41 0x42 0x43 version = 0x61626364 attr_count = 0x65667678 . . . a

Re: Reading binary data

2008-09-10 Thread Aaron "Castironpi" Brady
On Sep 10, 1:12 pm, Aaron Scott <[EMAIL PROTECTED]> wrote: > Sorry, I had posted the wrong error. The error I am getting is: > >      struct.error: unpack requires a string argument of length 12 > > which doesn't make sense to me, since I'm specifically asking for 11. > Just for kicks, if I change

Re: Reading binary data

2008-09-10 Thread Jon Clements
On Sep 10, 7:16 pm, Aaron Scott <[EMAIL PROTECTED]> wrote: > Taking everything into consideration, my code is now: > > import struct > file = open("test.gde", "rb") > signature = file.read(3) > version, attr_count = struct.unpack('II', file.read(8)) > print signature, version, attr_count > for idx

Re: Reading binary data

2008-09-10 Thread Roel Schroeven
Aaron Scott schreef: Sorry, I had posted the wrong error. The error I am getting is: struct.error: unpack requires a string argument of length 12 which doesn't make sense to me, since I'm specifically asking for 11. That's because of padding. According to the docs, "By default, C numbers

Re: Reading binary data

2008-09-10 Thread Aaron Scott
Taking everything into consideration, my code is now: import struct file = open("test.gde", "rb") signature = file.read(3) version, attr_count = struct.unpack('II', file.read(8)) print signature, version, attr_count for idx in xrange(attr_count): attr_id, attr_val_len = struct.unpack('II',

Re: Reading binary data

2008-09-10 Thread Aaron Scott
Sorry, I had posted the wrong error. The error I am getting is: struct.error: unpack requires a string argument of length 12 which doesn't make sense to me, since I'm specifically asking for 11. Just for kicks, if I change the line to print struct.unpack('3sII', file.read(12)) I get t

Re: Reading binary data

2008-09-10 Thread Jon Clements
On Sep 10, 6:45 pm, Aaron Scott <[EMAIL PROTECTED]> wrote: > > CORRECTION: '3cII' should be '3sII'. > > Even with the correction, I'm still getting the error. Me being silly... Quick fix: signature = file.read(3) then the rest can stay the same, struct.calcsize('3sII') expects a 12 byte string, w

Re: Reading binary data

2008-09-10 Thread Wojtek Walczak
On Wed, 10 Sep 2008 10:43:31 -0700 (PDT), Aaron Scott wrote: >> signature, version, attr_count = struct.unpack('3cII', >> yourfile.read(11)) >> > > This line is giving me an error: > > Traceback (most recent call last): > File "test.py", line 19, in > signature, version, attr_count = struct.

Re: Reading binary data

2008-09-10 Thread Aaron Scott
> CORRECTION: '3cII' should be '3sII'. Even with the correction, I'm still getting the error. -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading binary data

2008-09-10 Thread Aaron Scott
> signature, version, attr_count = struct.unpack('3cII', > yourfile.read(11)) > This line is giving me an error: Traceback (most recent call last): File "test.py", line 19, in signature, version, attr_count = struct.unpack('3cII', file.read(12)) ValueError: too many values to unpack -- htt

Re: Reading binary data

2008-09-10 Thread Jon Clements
On 10 Sep, 18:33, Jon Clements <[EMAIL PROTECTED]> wrote: > On 10 Sep, 18:14, Aaron Scott <[EMAIL PROTECTED]> wrote: > > > > > I've been trying to tackle this all morning, and so far I've been > > completely unsuccessful. I have a binary file that I have the > > structure to, and I'd like to read i

Re: Reading binary data

2008-09-10 Thread Jon Clements
On 10 Sep, 18:14, Aaron Scott <[EMAIL PROTECTED]> wrote: > I've been trying to tackle this all morning, and so far I've been > completely unsuccessful. I have a binary file that I have the > structure to, and I'd like to read it into Python. It's not a > particularly complicated file. For instance:

Reading binary data

2008-09-10 Thread Aaron Scott
I've been trying to tackle this all morning, and so far I've been completely unsuccessful. I have a binary file that I have the structure to, and I'd like to read it into Python. It's not a particularly complicated file. For instance: signature char[3] "GDE" version uint32 2 attr_co

Re: Help reading binary data from files

2007-02-06 Thread John Machin
On Feb 7, 9:34 am, "jeff" <[EMAIL PROTECTED]> wrote: > On Feb 6, 4:01 pm, "jeff" <[EMAIL PROTECTED]> wrote: > > > > > I am stumped trying to read binary data from simple files. Here is a > > code snippet, where I am trying to simply print little-endian encoded > > data from files in a directory. >

Re: Help reading binary data from files

2007-02-06 Thread John Machin
On Feb 7, 9:01 am, "jeff" <[EMAIL PROTECTED]> wrote: > I am stumped trying to read binary data from simple files. Here is a > code snippet, where I am trying to simply print little-endian encoded > data from files in a directory. > > for name in os.listdir(DOWNLOAD_DIR): > file

Re: Help reading binary data from files

2007-02-06 Thread jeff
On Feb 6, 4:01 pm, "jeff" <[EMAIL PROTECTED]> wrote: > I am stumped trying to read binary data from simple files. Here is a > code snippet, where I am trying to simply print little-endian encoded > data from files in a directory. > > for name in os.listdir(DOWNLOAD_DIR): > file

Re: Help reading binary data from files

2007-02-06 Thread Gabriel Genellina
En Tue, 06 Feb 2007 19:01:20 -0300, jeff <[EMAIL PROTECTED]> escribió: > I am stumped trying to read binary data from simple files. Here is a > code snippet, where I am trying to simply print little-endian encoded > data from files in a directory. > > for name in os.listdir(DOWNLOAD_DIR): >

Re: Help reading binary data from files

2007-02-06 Thread Grant Edwards
On 2007-02-06, jeff <[EMAIL PROTECTED]> wrote: > I am stumped trying to read binary data from simple files. Here is a > code snippet, where I am trying to simply print little-endian encoded > data from files in a directory. > > for name in os.listdir(DOWNLOAD_DIR): > filename =

Help reading binary data from files

2007-02-06 Thread jeff
I am stumped trying to read binary data from simple files. Here is a code snippet, where I am trying to simply print little-endian encoded data from files in a directory. for name in os.listdir(DOWNLOAD_DIR): filename = s.path.join(DOWNLOAD_DIR, name) if os.pa

Re: reading binary data written in C

2006-03-22 Thread Sheldon
Thanks, I later discovered that it was a big edian binary as well. Sheldon -- http://mail.python.org/mailman/listinfo/python-list

Re: reading binary data written in C

2006-03-22 Thread Grant Edwards
On 2006-03-22, Sheldon <[EMAIL PROTECTED]> wrote: > I have a script that I want to use to read some binary lon and lat data > that was written with a C program. http://www.python.org/doc/current/lib/module-struct.html -- Grant Edwards grante Yow! UH-OH!! We're out

reading binary data written in C

2006-03-22 Thread Sheldon
Hi, I have a script that I want to use to read some binary lon and lat data that was written with a C program. My script looks like this:  lat = open(lat_file,'rb').read() lat = Numeric.fromstring(lat) print len(lat) print lat[0] Results: 1476225 -995001790 Or using the Float typecode: Results

Re: Reading binary data

2005-11-23 Thread Thomas Heller
"David M" <[EMAIL PROTECTED]> writes: > Thanks but the C Struct describing the data doesn't match up with the > list on the module-struct page. > > this is the acct.h file [...] Tooting my ctypes horn (sorry for that): [EMAIL PROTECTED]:~/ctypes> locate acct.h /usr/include/linux/acct.h /usr/incl

Re: Reading binary data

2005-11-23 Thread Fredrik Lundh
"David M" wrote: > What are u_ini16_t and comp_t? comp_t is explained in the file you posted: > /* > comp_t is a 16-bit "floating" point number with a 3-bit base 8 > exponent and a 13-bit fraction. See linux/kernel/acct.c for the > specific encoding system used. > */ > > typedef u_int16_t com

Re: Reading binary data

2005-11-23 Thread Grant Edwards
In comp.lang.python, "David M" wrote: > Thanks but the C Struct describing the data doesn't match up with the > list on the module-struct page. Then you're going to have to do some bit-bashing. > comp_t is a 16-bit "floating" point number with a 3-bit base 8 > exponent and a 13-bit fraction.

Re: Reading binary data

2005-11-23 Thread David M
Thanks but the C Struct describing the data doesn't match up with the list on the module-struct page. this is the acct.h file #ifndef _SYS_ACCT_H #define _SYS_ACCT_H 1 #include #define __need_time_t #include #include __BEGIN_DECLS #define ACCT_COMM 16 /* comp_t is a 16-bit "floating

Re: Reading binary data

2005-11-23 Thread Fredrik Lundh
David M wrote: > OK so here is my task. I want to get at the data stored in > /var/account/pacct, which stores process accounting data, so that I can > make it into a more human understandable format then what the program > sa can do. The thing is, its in a binary format and an example program >

Re: Reading binary data

2005-11-23 Thread Grant Edwards
On 2005-11-23, David M <[EMAIL PROTECTED]> wrote: > OK so here is my task. I want to get at the data stored in > /var/account/pacct, which stores process accounting data, so that I can > make it into a more human understandable format then what the program > sa can do. The thing is, its in a bina

Reading binary data

2005-11-23 Thread David M
OK so here is my task. I want to get at the data stored in /var/account/pacct, which stores process accounting data, so that I can make it into a more human understandable format then what the program sa can do. The thing is, its in a binary format and an example program that reads some data from