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 ...

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

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(),

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 =

[issue23004] mock_open() should allow reading binary data

2015-08-07 Thread Berker Peksag
Berker Peksag added the comment: data_as_list = read_data.splitlines(True) is not actually the equivalent of data_as_list = [l + sep for l in read_data.split(sep)] It will change the behavior of the _iterate_read_data helper. See the comment at

[issue23004] mock_open() should allow reading binary data

2015-08-07 Thread R. David Murray
R. David Murray added the comment: splitlines(keepends=True) is not ever equivalent to splitting by just '\n'. I don't know the details here, but switching to that would certainly be a behavior change. (Especially if the code path also applies to non-binary data!):

[issue23004] mock_open() should allow reading binary data

2015-08-06 Thread Berker Peksag
Berker Peksag added the comment: Thanks for the patch, Aaron(also thanks to Demian for reviews). I've fixed the merge conflict and added more tests. -- resolution: - fixed stage: commit review - resolved status: open - closed ___ Python tracker

[issue23004] mock_open() should allow reading binary data

2015-08-06 Thread Roundup Robot
Roundup Robot added the comment: New changeset 3d7adf5b3fb3 by Berker Peksag in branch '3.4': Issue #23004: mock_open() now reads binary data correctly when the type of read_data is bytes. https://hg.python.org/cpython/rev/3d7adf5b3fb3 New changeset 526a186de32d by Berker Peksag in branch

[issue23004] mock_open() should allow reading binary data

2015-08-06 Thread Robert Collins
Robert Collins added the comment: Post merge review: looks like data_as_list = read_data.splitlines(True) would be a little cleaner. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004

[issue23004] mock_open() should allow reading binary data

2015-08-06 Thread Berker Peksag
Changes by Berker Peksag berker.pek...@gmail.com: -- assignee: - berker.peksag ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___ ___

[issue23004] mock_open() should allow reading binary data

2015-07-14 Thread Robert Collins
Changes by Robert Collins robe...@robertcollins.net: -- nosy: +rbcollins versions: +Python 3.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___

[issue23004] mock_open() should allow reading binary data

2015-03-01 Thread Berker Peksag
Berker Peksag added the comment: LGTM. -- components: +Library (Lib) stage: patch review - commit review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___

[issue23004] mock_open() should allow reading binary data

2015-02-12 Thread Demian Brecht
Changes by Demian Brecht demianbre...@gmail.com: -- nosy: -demian.brecht ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___ ___

[issue23004] mock_open() should allow reading binary data

2014-12-31 Thread Demian Brecht
Demian Brecht added the comment: A few more comments were left in Rietveld for you, likely hidden by spam filters. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___

[issue23004] mock_open() should allow reading binary data

2014-12-19 Thread Aaron Hill
Aaron Hill added the comment: I've fixed the formatting issues. -- Added file: http://bugs.python.org/file37510/mock-open-allow-binary-data-fix-formatting.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004

[issue23004] mock_open() should allow reading binary data

2014-12-15 Thread Aaron Hill
Aaron Hill added the comment: I've fixed the issues you pointed out. Is there a better way than uploading a new patch file to make changes? -- Added file: http://bugs.python.org/file37458/mock-open-allow-binary-without-coerce-fixup.patch ___ Python

[issue23004] mock_open() should allow reading binary data

2014-12-15 Thread Demian Brecht
Demian Brecht added the comment: Thanks for the updated patch, looks good to me. If you haven't already read it, the patch workflow is here: https://docs.python.org/devguide/patch.html and is the only workflow currently available. -- ___ Python

[issue23004] mock_open() should allow reading binary data

2014-12-15 Thread Berker Peksag
Changes by Berker Peksag berker.pek...@gmail.com: -- stage: needs patch - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___ ___

[issue23004] mock_open() should allow reading binary data

2014-12-14 Thread Aaron Hill
Aaron Hill added the comment: Thanks, I've fixed that. Not sure why I thought decoding and re-encoding would work with any binary data. I've also updated one of the tests to use non-utf8-decodeable binary data, to prevent a future regression. -- Added file:

[issue23004] mock_open() should allow reading binary data

2014-12-14 Thread Demian Brecht
Demian Brecht added the comment: Thanks again for the update Aaron, I've left a couple small comments in Rietveld. Other than those, the patch looks good to me. Thanks for the contribution! -- ___ Python tracker rep...@bugs.python.org

[issue23004] mock_open() should allow reading binary data

2014-12-13 Thread Aaron Hill
Aaron Hill added the comment: I've created a new patch, which addresses the problem. Your example now currently returns [b'foo\n', b'bar\n'] -- Added file: http://bugs.python.org/file37440/mock-open-allow-binary-data-updated.patch ___ Python

[issue23004] mock_open() should allow reading binary data

2014-12-13 Thread Demian Brecht
Demian Brecht added the comment: Thanks for the update, but this doesn't quite work either as you're assuming utf-8 (which is what .encode() and .decode() default to). For example, when using latin-1: m = mock_open(read_data= b'\xc6') with patch('__main__.open', m, create=True) : ...

[issue23004] mock_open() should allow reading binary data

2014-12-12 Thread Aaron Hill
Aaron Hill added the comment: I've created a patch that fixes this, and added an accompanying unit test (which fails without the change). -- keywords: +patch nosy: +Aaron1011 Added file: http://bugs.python.org/file37435/mock-open-allow-binary-data.patch

[issue23004] mock_open() should allow reading binary data

2014-12-12 Thread Demian Brecht
Demian Brecht added the comment: Thanks for the patch Aaron. Unfortunately this doesn't quite fix the issue. There are two problems with the patch: If a bytes object is passed into mock_open, I'd expect a bytes object in the output. In your patch, not only is this not the case (the output is

[issue23004] mock_open() should allow reading binary data

2014-12-12 Thread Demian Brecht
Demian Brecht added the comment: There are two problems with the patch That was intended to be removed after I changed the wording :P -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004

[issue23004] mock_open() should allow reading binary data

2014-12-07 Thread Jesús Cea Avión
was introduced as result of issue #17467. I add those people to the nosy list. -- keywords: easy messages: 232271 nosy: a.badger, jcea, michael.foord priority: normal severity: normal status: open title: mock_open() should allow reading binary data versions: Python 3.5

[issue23004] mock_open() should allow reading binary data

2014-12-07 Thread Jesús Cea Avión
Changes by Jesús Cea Avión j...@jcea.es: -- dependencies: +Enhancement: give mock_open readline() and readlines() methods ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004 ___

[issue23004] mock_open() should allow reading binary data

2014-12-07 Thread Berker Peksag
Changes by Berker Peksag berker.pek...@gmail.com: -- nosy: +berker.peksag stage: - needs patch type: - behavior versions: +Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23004

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:/ Open db

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

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

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 hari...@gmail.com 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)

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

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:

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 it into

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 module signature, version, attr_count = struct.unpack('3cII', file.read(12)) ValueError: too many values to unpack --

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 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 module signature, version, attr_count =

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,

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

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 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 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 in

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 the

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 . . .

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 in

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_len =

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

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 =

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 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): filename =

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): filename =

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. for name in

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:

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

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

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

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 binary

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 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 features.h #define __need_time_t #include time.h #include sys/types.h __BEGIN_DECLS #define ACCT_COMM 16 /*

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. See

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 comp_t; as

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