a.index(float('nan')) fails
>>> a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> a.index(float('nan')) Traceback (most recent call last): File "", line 1, in ValueError: list.index(x): x not in list That means, the function .index() cannot detect nan values. It happens on both Python 2.6 and Python 3.1 Is this a bug? Or I am not using .index() correctly? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: a.index(float('nan')) fails
On Thursday, October 25, 2012 7:16:02 PM UTC-7, Cameron Simpson wrote: Of course!! How could I get into that trap?? Thanks to you & to Terry -- http://mail.python.org/mailman/listinfo/python-list
global vars across modules
I need to use global var across files/modules: # file_1.py a = 0 def funct_1() : a = 1 # a is global print(a) # file_2.py from file_1 import * def main() : funct_1() a = 2 # a is local, it's not imported print(a) Here above 'a' is not imported from file_1, it's local. The only way I was able to access the global 'a' is the following: # file_2.py from file_1 import * import file_1 def main() : funct_1() file_1.a = 2# a is the global from file_1 print(file_1.a) Question: How can I access to the global 'a' in file_2 without resorting to the whole name 'file_1.a' ? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: global vars across modules
On Sunday, April 22, 2012 12:48:23 PM UTC-7, Roy Smith wrote: > Answer 1: You can't. > > Answer 2: You might want to look at thread local storage > (http://docs.python.org/library/threading.html#threading.local). > > Answer 3: Are you sure you really want to do this? Thanks! Here is what I need to do, perhaps you can give me some hints. A generic module, used across different independent programs, puts its computing results in a var fairly big, ~50KB. I need the functions in these programs to access that var. No assignment will be made to that var, it will just be accessed to parse its content. How can I do? I cannot think of making that var local and 'returning' ~50KB all the times the module is called. Any hint...? -- http://mail.python.org/mailman/listinfo/python-list
Sorting (deeply) nested lists
I cannot resolve this on my own. Need help, please... nestedTuples = [ [ (L0t0e0, L0t0e1, L0t0e2), (L0t1e0, 2, L0t1e2), (L0t2e0, L0t2e1, L0t2e2) ], [ (L1t0e0, L1t0e1, L1t0e2), (L1t1e0, 0, L1t1e2), (L1t2e0, L1t2e1, L1t2e2) ], [ (L2t0e0, L2t0e1, L2t0e2), (L2t1e0, 1, L2t1e2), (L2t2e0, L2t2e1, L2t2e2) ] ] With LNtXeY I mean the element Y in the tuple X of the list N. How can I sort nestedTuples by, say, the 2nd element in the 2nd tuple of each list? The above should get sorted as : nestedTuples = [ [ (L1t0e0, L1t0e1, L1t0e2), (L1t1e0, 0, L1t1e2), (L1t2e0, L1t2e1, L1t2e2) ], [ (L2t0e0, L2t0e1, L2t0e2), (L2t1e0, 1, L2t1e2), (L2t2e0, L2t2e1, L2t2e2) ], [ (L0t0e0, L0t0e1, L0t0e2), (L0t1e0, 2, L0t1e2), (L0t2e0, L0t2e1, L0t2e2) ] ] Thanks so much!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting (deeply) nested lists
On Saturday, March 2, 2013 9:36:43 AM UTC-8, Peter Otten wrote: > > You can also write this as > > namedTuples.sort(key=lambda item: item[1][1]) > That's exactly what I did before and got "IndexError: list index out of range". So, I thought my lambda was wrong and posted here. Now, having seen you reply, I dug deeper and... of course I had IndexError: the list was horribly empty! Thanks so much for replying so quickly, Peter! -- http://mail.python.org/mailman/listinfo/python-list