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 ...
>
> 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
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(),
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 =
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
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!):
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
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
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
Changes by Berker Peksag berker.pek...@gmail.com:
--
assignee: - berker.peksag
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23004
___
___
Changes by Robert Collins robe...@robertcollins.net:
--
nosy: +rbcollins
versions: +Python 3.6
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23004
___
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
___
Changes by Demian Brecht demianbre...@gmail.com:
--
nosy: -demian.brecht
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23004
___
___
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
___
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
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
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
Changes by Berker Peksag berker.pek...@gmail.com:
--
stage: needs patch - patch review
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23004
___
___
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:
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
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
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) :
...
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
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
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
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
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
___
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
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
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
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
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)
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
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:
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
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
--
CORRECTION: '3cII' should be '3sII'.
Even with the correction, I'm still getting the error.
--
http://mail.python.org/mailman/listinfo/python-list
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 =
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,
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
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',
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
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
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
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
. . .
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
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 =
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
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 =
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):
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 =
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 =
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
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:
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
Thanks,
I later discovered that it was a big edian binary as well.
Sheldon
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
/*
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
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
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
63 matches
Mail list logo