Re: How to retrieve the filename of a module
mku wrote: Hi, thereĀ“s a function inside a module. How can these function retrieve the path+name of his module ? (The path is most important). That should also work if the module is part of a package. Thanks in advance Martin Try the following in the function: import traceback f = traceback.extract_stack(limit=2) If you output f to the interpreter, you'll see the filename but I don't know what position in the output list it is guaranteed to be. Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: array subset could be improved? -repost ;)
With the new numeric, you'll be able to do: negatives = a[a0] Cheers, f Ooh, that's nice. Jim -- http://mail.python.org/mailman/listinfo/python-list
my array subset method could be improved?
Hi all I have an array a=array([2,3,1]). I want to extract an array with all the elements of a that are less than 0. Method 1. new = array([i for i in a if i 0]) Method 2. new = a[nonzero(a0)] I'm using Numeric arrays but can't seem to find a function that does this. Am I missing a more obvious way to do it quickly? Thanks Jim -- http://mail.python.org/mailman/listinfo/python-list
array subset could be improved? -repost ;)
Hi all I have an array a=array([2,3,-1]). I want to extract an array with all the elements of a that are less than 0. Method 1. new = array([i for i in a if i 0]) Method 2. new = a[nonzero(a0)] I'm using Numeric arrays but can't seem to find a function that does this. Am I missing a more obvious way to do it quickly? Thanks Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: my array subset method could be improved?
new = Numeric.compress(Numeric.less(a,0),a) Ah, thank you! Sorry about subject mangle, I gave a silly example first time round. Jim -- http://mail.python.org/mailman/listinfo/python-list
assignment, references and list comprehension
Hi everyone Was just posting a question as I got confused with a big messy sheaf of code when I thought I should make a simple example myself. Since I did I thought I'd post it for the good of mankind. I was confused as to whether the assignment of a result of a list comprehension created references to the orginal objects... and it does (at least for my self-defined object). e.g. initArrrgs = [pick me,not me] class MyObject: def __init__(arg): self.argument = arg; myObjects = [MyObject(initarg) for initarg in initArrrgs] myObjects2 = [ob for ob in myObjects if ob.argument == pick me] Then the following interrogation myObjects2[0].argument 'pick me' myObjects2[0].argument='juicy' myObjects2[0].argument 'juicy' myObjects[0].argument 'juicy' Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: assignment, references and list comprehension
trust me, it works the same way for all objects. Yes, it was lack of trust that led me on a 2 hour re-write to avoid creating subsets of object lists as I thought they were being copied. In fact it was another error... huh. I now know better. Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: assignment, references and list comprehension
reading this may help: http://effbot.org/zone/python-objects.htm /F site bookmarked ;) -- http://mail.python.org/mailman/listinfo/python-list