Re: Storing dictionary locations as a string and using eval - alternatives?

2015-08-19 Thread dieter
Victor Hooi writes: > ... I did not read your message body - just your "subject". Instead of (the potentially insecure) "eval", I use "json.loads" (combined with a "json.dumps" to get the "json" representation). See the "json" module documentation. -- https://mail.python.org/mailman/listinfo/py

Re: Storing dictionary locations as a string and using eval - alternatives?

2015-08-19 Thread Steven D'Aprano
On Thursday 20 August 2015 13:59, Victor Hooi wrote: > Hi, > > I have a textfile with a bunch of JSON objects, one per line. > > I'm looking at parsing each of these, and extract some metrics from each > line. > > I have a dict called "metrics_to_extract", containing the metrics I'm > looking a

Storing dictionary locations as a string and using eval - alternatives?

2015-08-19 Thread Victor Hooi
Hi, I have a textfile with a bunch of JSON objects, one per line. I'm looking at parsing each of these, and extract some metrics from each line. I have a dict called "metrics_to_extract", containing the metrics I'm looking at extracting. In this, I store a name used to identify the metric, alon

Re: Check if dictionary empty with == {}

2015-08-19 Thread Steven D'Aprano
On Thursday 20 August 2015 08:57, Anton wrote: > Probably a silly question. > Let's say I have a dictionary mydict and I need to test if a dictionary is > empty. > > I would use > > if not mydict: > """do something""" > > But I just came across a line of code like: > > if mydict == {}: >

Re: JSON Object to CSV file

2015-08-19 Thread ryguy7272
On Wednesday, June 17, 2015 at 11:00:24 AM UTC-4, kbtyo wrote: > I would like to have this JSON object written out to a CSV file so that the > keys are header fields (for each of the columns) and the values are values > that are associated with each header field. Is there a best practice for > w

Re: JSON Object to CSV Question

2015-08-19 Thread ryguy7272
On Thursday, June 18, 2015 at 2:59:11 AM UTC-4, kbtyo wrote: > Good Evening Everyone: > > > I would like to have this JSON object written out to a CSV file so that the > keys are header fields (for each of the columns) and the values are values > that are associated with each header field. Is t

Re: Check if dictionary empty with == {}

2015-08-19 Thread Skip Montanaro
On Wed, Aug 19, 2015 at 6:33 PM, MRAB wrote: > Well, that depends on the intention. > > Is it checking whether the dictionary is empty, or whether it's an > empty dictionary (and not, say, an empty list)? > Sure, that's a possibility. I would argue that "mydict == {}" is also not the idiomatic w

Re: Check if dictionary empty with == {}

2015-08-19 Thread Tim Chase
On 2015-08-19 15:57, Anton wrote: > Probably a silly question. > Let's say I have a dictionary mydict and I need to test if a > dictionary is empty. > > I would use > > if not mydict: > """do something""" > > But I just came across a line of code like: > > if mydict == {}: > """do some

Re: Check if dictionary empty with == {}

2015-08-19 Thread MRAB
On 2015-08-20 00:15, Skip Montanaro wrote: Comparison against {} will be less efficient. You need to create a dictionary every time instead of just checking the length of your dictionary, which is likely stored in the header. So, it will work, but certainly isn't idiomatic Python. Well, that de

Re: Check if dictionary empty with == {}

2015-08-19 Thread Skip Montanaro
Comparison against {} will be less efficient. You need to create a dictionary every time instead of just checking the length of your dictionary, which is likely stored in the header. So, it will work, but certainly isn't idiomatic Python. Skip -- https://mail.python.org/mailman/listinfo/python-li

Check if dictionary empty with == {}

2015-08-19 Thread Anton
Probably a silly question. Let's say I have a dictionary mydict and I need to test if a dictionary is empty. I would use if not mydict: """do something""" But I just came across a line of code like: if mydict == {}: """do something""" which seems odd to me, but maybe there is a valid

Re: Python re to extract useful information from each line

2015-08-19 Thread Paul McGuire
Here is a first shot at a pyparsing parser for these lines: from pyparsing import * SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY = map(CaselessKeyword, "SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY".split(',')) integer = Word(nums) ipA

Re: Logging to a file from a C-extension

2015-08-19 Thread Stefan Behnel
Al Pfalzgraf schrieb am 18.08.2015 um 15:07: > If a logging file is opened at the level of a Python application, how > would the log file name be communicated to a C-extension so that logging > from the extension would be sent to the same log file? Writing to the file directly (as was suggested) m

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread ryguy7272
On Wednesday, August 19, 2015 at 1:14:44 PM UTC-4, Petite Abeille wrote: > > On Aug 19, 2015, at 7:01 PM, Denis McMahon wrote: > > > > Downloading xml from the web is easy > > > > writing csv or txt is easy > > > > The tricky bit is converting the xml you have into the csv or text data > > you

ANN: Wing IDE 5.1.6 released

2015-08-19 Thread Wingware
Hi, Wingware has released version 5.1.6 of Wing IDE, our cross-platform integrated development environment for the Python programming language. Wing IDE features a professional code editor with vi, emacs, visual studio, and other key bindings, auto-completion, call tips, context-sensitive au

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread Petite Abeille
> On Aug 19, 2015, at 7:01 PM, Denis McMahon wrote: > > Downloading xml from the web is easy > > writing csv or txt is easy > > The tricky bit is converting the xml you have into the csv or text data > you want. > curl | xml2 | 2csv http://www.ofb.net/~egnor/xml2/ref -- https://mail.pytho

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread Denis McMahon
On Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 wrote: [stuff] Downloading xml from the web is easy writing csv or txt is easy The tricky bit is converting the xml you have into the csv or text data you want. And to do that, you need to understand the structure of the xml data that you are rec

Re: Regular expression and substitution, unexpected duplication

2015-08-19 Thread Laurent Pointal
MRAB wrote: > On 2015-08-18 22:42, Laurent Pointal wrote: >> Hello, >> ellipfind_re = re.compile(r"((?=\.\.\.)|…)", re.IGNORECASE|re.VERBOSE) >> ellipfind_re.sub(' ... ', >> "C'est un essai... avec différents caractères… pour voir.") > (?=...) is a lookahead; a non-capture group is (?:..

Re: regex recursive matching (regex 2015.07.19)

2015-08-19 Thread Ben Bacarisse
MRAB writes: > On 2015-08-18 22:55, Ben Bacarisse wrote: >> Neal Becker writes: >> >>> Trying regex 2015.07.19 >>> >>> I'd like to match recursive parenthesized expressions, with groups such that >>> '(a(b)c)' >>> >>> would give >>> group(0) -> '(a(b)c)' >>> group(1) -> '(b)' >>> >>> but that's

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread Laura Creighton
In a message of Wed, 19 Aug 2015 06:32:46 -0700, ryguy7272 writes: >Well, yes, I was originally trying to do it it R, but I couldn't get >it working, so I thought I'd try to do it in Python. That was a >sample R script. Can I do essentially the same thing in Python? Can >I read the XML from the

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread Joel Goldstick
> > > Well, yes, I was originally trying to do it it R, but I couldn't get it > working, so I thought I'd try to do it in Python. That was a sample R > script. Can I do essentially the same thing in Python? Can I read the XML > from the web? > http://www.usda.gov/oce/commodity/wasde/report_fo

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread ryguy7272
On Wednesday, August 19, 2015 at 8:21:50 AM UTC-4, Laura Creighton wrote: > In a message of Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 writes: > >I'm trying to get R to download the data from here: > > > >http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > > >

Re: Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread Laura Creighton
In a message of Wed, 19 Aug 2015 04:57:44 -0700, ryguy7272 writes: >I'm trying to get R to download the data from here: > >http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml > > ># install and load the necessary package >install.packages("XML") >library(XML) ># Sa

Re: Permission denied error in download nltk_data...

2015-08-19 Thread Steven D'Aprano
On Wed, 19 Aug 2015 04:57 pm, Dwight GoldWinde wrote: > Please helpŠ > > Using this code: > > import nltk > nltk.download('maxent_treebank_pos_tagger¹) > > > I get this error: [...] >os.mkdir(download_dir) > > PermissionError: [Errno 13] Permission denied: > '/Users/dwightgoldwindex/nltk_

Can I download XML data from the web and save, in as CSV or TXT delimitation?

2015-08-19 Thread ryguy7272
I'm trying to get R to download the data from here: http://www.usda.gov/oce/commodity/wasde/report_format/latest-July-2015-New-Format.xml # install and load the necessary package install.packages("XML") library(XML) # Save the URL of the xml file in a variable xml.url <- "http://www.usda.gov/o

Why the different parameter signatures to indicate blocking/timeouts.

2015-08-19 Thread Antoon Pardon
I have been looking through the threading module and I am a bit annoyed at the different signatures for indicating whether some calls should block or not and the timeout. On the one hand we have the acquire on locks with the following signature: def accquire(blocking=True, timeout=-1) On the othe

ANN: eGenix mxODBC 3.3.5 - Python ODBC Database Interface

2015-08-19 Thread eGenix Team: M.-A. Lemburg
ANNOUNCING eGenix.com mxODBC Python ODBC Database Interface Version 3.3.5 mxODBC is our commercially supported Python extension providing

Permission denied error in download nltk_data...

2015-08-19 Thread Dwight GoldWinde
Please helpŠ Using this code: import nltk nltk.download('maxent_treebank_pos_tagger¹) I get this error: [nltk_data] Downloading package maxent_treebank_pos_tagger to [nltk_data]/Users/dwightgoldwindex/nltk_data... Traceback (most recent call last): File "test short.py", line 18, in n

Re: execute commands as su on remote server

2015-08-19 Thread Laura Creighton
In a message of Wed, 19 Aug 2015 10:44:53 +0200, Laura Creighton writes: >I haven't tried this but fabric looks encouraging: > >>From >>http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.run > > fabric.operations.run(*args, **kwargs) > >Run a shell command on a remote

Re: execute commands as su on remote server

2015-08-19 Thread Laura Creighton
I haven't tried this but fabric looks encouraging: >From >http://docs.fabfile.org/en/latest/api/core/operations.html#fabric.operations.run fabric.operations.run(*args, **kwargs) Run a shell command on a remote host. ... Any text entered in your local terminal will be forwarded to

Re: Logging to a file from a C-extension

2015-08-19 Thread Laura Creighton
In a message of Tue, 18 Aug 2015 08:07:51 -0500, Al Pfalzgraf writes: > If a logging file is opened at the level of a Python application, how would > the log file name be communicated to a C-extension so that logging from the > extension would be sent to the same log file? To convert a file to a

Re: execute commands as su on remote server

2015-08-19 Thread harirammanohar159
On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com wrote: > execute commands as su on remote server > > Postby hariram » Mon Aug 17, 2015 4:02 am > Needed: > I need to execute commands after doing su to other user on remote server(not > sudo which doesn't require password) how i

Re: execute commands as su on remote server

2015-08-19 Thread harirammanohar159
On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm...@gmail.com wrote: > execute commands as su on remote server > > Postby hariram » Mon Aug 17, 2015 4:02 am > Needed: > I need to execute commands after doing su to other user on remote server(not > sudo which doesn't require password) how i