Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Ian Kelly
On Tue, Jun 23, 2015 at 7:06 PM, Paul Rubin wrote: > Chris Angelico writes: >>> Would I have to do an O(n) search to find my key? >> Iterate over it - it's an iterable view in Py3 - and compare. > > I think the question was whether the O(n) search could be avoided, not > how to do it. I don't se

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Peter Otten
Dan Stromberg wrote: > I know that sounds strange: usually we look up values by key, not keys. > > But suppose you have a strange key type that despite being "equal", is > not identical in some fields, and you need to see those fields. > > Is there a way of getting the key used by the dictionary

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Steven D'Aprano
On Wed, 24 Jun 2015 11:32 am, MRAB wrote: > On 2015-06-24 01:21, Dan Stromberg wrote: >> I know that sounds strange: usually we look up values by key, not keys. >> >> But suppose you have a strange key type that despite being "equal", is >> not identical in some fields, and you need to see those f

Re: Organizing function calls once files have been moved to a directory

2015-06-23 Thread Steven D'Aprano
On Wed, 24 Jun 2015 06:16 am, kbtyo wrote: > I am working on a workflow module that will allow one to recursively check > for file extensions and if there is a match move them to a folder for > processing (parsing, data wrangling etc). > > I have a simple search process, and log for the files tha

Re: To write headers once with different values in separate row in CSV

2015-06-23 Thread Steven D'Aprano
On Wed, 24 Jun 2015 03:15 am, Sahlusar wrote: > That is not the underlying issue. Any thoughts or suggestions would be > very helpful. Thank you for spending over 100 lines to tell us what is NOT the underlying issue. I will therefore tell you what is NOT the solution to your problem (whatever i

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Steven D'Aprano
On Wed, 24 Jun 2015 10:21 am, Dan Stromberg wrote: > I know that sounds strange: usually we look up values by key, not keys. > > But suppose you have a strange key type that despite being "equal", is > not identical in some fields, and you need to see those fields. > > Is there a way of getting

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread MRAB
On 2015-06-24 01:21, Dan Stromberg wrote: I know that sounds strange: usually we look up values by key, not keys. But suppose you have a strange key type that despite being "equal", is not identical in some fields, and you need to see those fields. Is there a way of getting the key used by the

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Paul Rubin
Chris Angelico writes: >> Would I have to do an O(n) search to find my key? > Iterate over it - it's an iterable view in Py3 - and compare. I think the question was whether the O(n) search could be avoided, not how to do it. I don't see a way to avoid it. There is fundamental brokenness in havi

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Ben Finney
Dan Stromberg writes: > On Tue, Jun 23, 2015 at 5:33 PM, Ben Finney > wrote: > > Dan Stromberg writes: > > > >> Is there a way of getting the key used by the dictionary, short of > >> storing a reference to it in the value, or using a second dictionary? > > > > The dictionary knows its keys an

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Paul Rubin
Dan Stromberg writes: > suppose you have a strange key type that despite being "equal", is > not identical in some fields Don't do that. You were asking for trouble and you got some. -- https://mail.python.org/mailman/listinfo/python-list

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Chris Angelico
On Wed, Jun 24, 2015 at 10:47 AM, Dan Stromberg wrote: > Would I have to do an O(n) search to find my key? Iterate over it - it's an iterable view in Py3 - and compare. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Dan Stromberg
On Tue, Jun 23, 2015 at 5:33 PM, Ben Finney wrote: > Dan Stromberg writes: > >> Is there a way of getting the key used by the dictionary, short of >> storing a reference to it in the value, or using a second dictionary? > > The dictionary knows its keys and can provide them on request. Call the >

Re: Looking up a dictionary _key_ by key?

2015-06-23 Thread Ben Finney
Dan Stromberg writes: > Is there a way of getting the key used by the dictionary, short of > storing a reference to it in the value, or using a second dictionary? The dictionary knows its keys and can provide them on request. Call the ‘dict.keys’ method to get them as a collection. -- \ “

Looking up a dictionary _key_ by key?

2015-06-23 Thread Dan Stromberg
I know that sounds strange: usually we look up values by key, not keys. But suppose you have a strange key type that despite being "equal", is not identical in some fields, and you need to see those fields. Is there a way of getting the key used by the dictionary, short of storing a reference to

Re: method returns object reference

2015-06-23 Thread Ned Batchelder
On Tuesday, June 23, 2015 at 2:32:55 PM UTC-4, Tim wrote: > I spent a while finding this problem which looks something like the old > "mutable default argument" problem. > http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments > > I'm not crystal clear on the details,

Re: Python File as the Default PDF handler for Windows

2015-06-23 Thread Mark Lawrence
On 23/06/2015 21:12, Dennis Lee Bieber wrote: On Tue, 23 Jun 2015 16:26:28 +0200 (CEST), Jean-Michel Pichavant declaimed the following: Just to update, you are correct, Chris, the file short name is passed into sys.argv. didn't need to add anything to the path. But a gotcha -- Windows didn't l

Organizing function calls once files have been moved to a directory

2015-06-23 Thread kbtyo
I am working on a workflow module that will allow one to recursively check for file extensions and if there is a match move them to a folder for processing (parsing, data wrangling etc). I have a simple search process, and log for the files that are present (see below). However, I am puzzled b

Re: To write headers once with different values in separate row in CSV

2015-06-23 Thread Saran Ahluwalia
It was an XML formatting issue; apparently you have to explicitly call a delimiter via the Command Prompt on my OS. IPython Notebook seems to make certain assumptions regarding read and write. On Tue, Jun 23, 2015 at 3:12 PM, John Gordon wrote: > In Sahlusar < > ahlusar.ahluwa...@gmail.com> wri

Re: method returns object reference

2015-06-23 Thread Ian Kelly
On Tue, Jun 23, 2015 at 12:32 PM, Tim wrote: > The code below prints the following two lines, showing how the 'newkey' is > now inside the Client response, even though it was set in the worker. This > must be bad practice! In my real code, the response is no longer an instance > variable, whi

Re: To write headers once with different values in separate row in CSV

2015-06-23 Thread John Gordon
In Sahlusar writes: > However, when I extrapolate this same logic with a list like: > ('Response.MemberO.PMembers.PMembers.Member.CurrentEmployer.EmployerAddress > .TimeAtPreviousAddress.', None), where the headers/columns are the first > item (only to be written out once) with different value

method returns object reference

2015-06-23 Thread Tim
I spent a while finding this problem which looks something like the old "mutable default argument" problem. http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments I'm not crystal clear on the details, but once I found it, the fix was easy. I'm posting here just because

To write headers once with different values in separate row in CSV

2015-06-23 Thread Sahlusar
I have the following script for writing out to CSV two items in a list to a CSV in such a format, such that if we have: L = [('A', 1), ('B', 2), ('C', 3), ('D', 4),('A', 5), ('B', 6), ('D', 8)] we want A B C D 1 2 3 4 5 6 8 And with this L = [('A', 1), ('B', 2), ('C', 3), ('D', 4),('D', 5)

Re: HOPE: A Python just-in-time compiler for astrophysical computations

2015-06-23 Thread Laurent Pointal
Mark Lawrence wrote: > Another beasty I've just stumbled across which you may find interesting > http://www.sciencedirect.com/science/article/pii/S2213133714000687 Why use a JIT complation when you could use some C++ generation then compilation as Python module, like with Pythran ? https://git

Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-23 Thread Terry Reedy
On 6/22/2015 9:32 PM, Paul Rubin wrote: Travis Griggs writes: The following seems to obtuse/clever for its own good: return sum(1 for _ in self.path.iterdir()) I disagree. For one who understands counting and Python, this is a direct way to define the count of a finite iterable. A fun

Re: Python File as the Default PDF handler for Windows

2015-06-23 Thread Chris Angelico
On Wed, Jun 24, 2015 at 12:26 AM, Jean-Michel Pichavant wrote: >> Just to update, you are correct, Chris, the file short name is passed >> into sys.argv. didn't need to add anything to the path. But a gotcha >> -- Windows didn't like my .py, clicking on the pdf causes Windows to >> complain about

Re: Python File as the Default PDF handler for Windows

2015-06-23 Thread Jean-Michel Pichavant
> Just to update, you are correct, Chris, the file short name is passed > into sys.argv. didn't need to add anything to the path. But a gotcha > -- Windows didn't like my .py, clicking on the pdf causes Windows to > complain about 'file x' is not a valid windows executable. I'm not an expert of w

Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard

2015-06-23 Thread Felix Yan
On 06/22/2015 07:51 PM, Tim Chase wrote: > On Win32, you'd need the Win32 add-on libraries to shove things onto > the clipboard, while under X, you'd need other facilities (either > using Tkinter or piping to something like xclip(1)), and yet another > way of doing things on MacOS. Or you may want

Re: Python File as the Default PDF handler for Windows

2015-06-23 Thread Naftali
On Thursday, June 18, 2015 at 5:05:15 PM UTC-4, Naftali wrote: > Long time lurker. > > I'm looking to register a python script as the default pdf reader for > windows. I assume I can just register the .py in the section windows section > for registering default handlers, but I'm wondering how t

Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-23 Thread Peter Otten
Travis Griggs wrote: > Subject nearly says it all. > > If i’m using pathlib, what’s the simplest/idiomatic way to simply count > how many files are in a given directory? > > I was surprised (at first) when > > len(self.path.iterdir()) > > I don’t say anything on the in the .stat() object t

Re: MGCP Server implementation

2015-06-23 Thread Laura Creighton
In a message of Mon, 22 Jun 2015 20:42:21 -, "Devaki Chokshi (dchokshi)" wr ites: >Hello, > >I have a use case where a SIP voice call will be passing through an MGCP >gateway. > >Is there a python implementation that simulates MGCP gateway/server? > >Thank you >Devaki Chokshi > >-- >https://m

Re: JSON Object to CSV File Troubleshooting

2015-06-23 Thread Sahlusar
On Tuesday, June 23, 2015 at 2:35:50 AM UTC-4, Denis McMahon wrote: > On Sun, 21 Jun 2015 16:56:27 -0700, Sahlusar wrote: > > > Here is an example XML document that I am working with: > > > You are welcome to contribute and provide me with feedback. Thank you > > for your continued feedback and g

Re: Simplest/Idiomatic way to count files in a directory (using pathlib)

2015-06-23 Thread Laura Creighton
I use len(list(self.path.iterdir())) You get an extra list created in there. Do you care? Laura -- https://mail.python.org/mailman/listinfo/python-list

Extract Stores from Store Locators

2015-06-23 Thread ilia . uk
Hi Everyone, I was curious whether there was a way to get a list of all stores from a store locator? Currently I am limited to 10 so using requests in python doesn't give me much advantage over the web-browser interface: import requests url = 'http://promotions.coral.co.uk/iframes/shop_locato

Re: MGCP Server implementation

2015-06-23 Thread Mark Lawrence
On 22/06/2015 21:42, Devaki Chokshi (dchokshi) wrote: Hello, I have a use case where a SIP voice call will be passing through an MGCP gateway. Is there a python implementation that simulates MGCP gateway/server? Thank you Devaki Chokshi There appears to be, but I'll let you type "python MG

Final CFP: 2015 Workshop on Exascale Multi/many Core Computing Systems (E-MuCoCoS)

2015-06-23 Thread SP
CALL FOR PAPERS 2015 Workshop on Exascale Multi/many Core Computing Systems (E-MuCoCoS) - Paper submission deadline: June 30, 2015 (firm deadline) - Workshop proceedings are published by the IEEE * CONTEXT Exascale computing will revolutionize computational science and engineering by providin

MGCP Server implementation

2015-06-23 Thread Devaki Chokshi (dchokshi)
Hello, I have a use case where a SIP voice call will be passing through an MGCP gateway. Is there a python implementation that simulates MGCP gateway/server? Thank you Devaki Chokshi -- https://mail.python.org/mailman/listinfo/python-list

ASA Conference on Statistical Practice - deadline Thursday

2015-06-23 Thread Adams, Jean
Python users, Abstracts are now being accepted for the 2016 ASA Conference on Statistical Practice, February 18-20, San Diego, CA, USA. Conference attendees are not typically familiar with Python. It would be great to have someone from the Python community give a brief overview of