status of new python.org
Is there any updated roadmap/schedule for the new python.org site ? It has been in beta mode at http://preview.python.org/ for several months but I can not find in there any indication of the progress or the possible date for publishing it. Most paragraphs are still with Lore Ipsum. -- https://mail.python.org/mailman/listinfo/python-list
Re: "Breaking" the __main__ script
On 14 mar, 12:34, vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like stop, break, end or something similar. > > What statement can I use? > > Vicente Soler Hola Vicente, You need a debugger. A practical solution to start with is to use an IDE with an integrated debugger. Stani's Python Editor (SPE) is a lightweight IDE with pdb integrated (with style checker also). It is a very good ide for learning (simple and not cluttered) but also for medium size applications (it is very well designed). atb Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: "Breaking" the __main__ script
On 14 mar, 20:35, Michael Rudolf wrote: > Am 14.03.2010 16:03, schrieb pyt...@bdurham.com: > > > Any reason you prefer PDB over WinPDB? > >http://winpdb.org/ > > Yes. I don't have Windows except one one PC :P WinPdb is crossplatform. Is build with -- http://mail.python.org/mailman/listinfo/python-list
Re: "Breaking" the __main__ script
On 14 mar, 20:35, Michael Rudolf wrote: > Am 14.03.2010 16:03, schrieb pyt...@bdurham.com: > > > Any reason you prefer PDB over WinPDB? > >http://winpdb.org/ > > Yes. I don't have Windows except one one PC :P Sorry, i hit the wrong key. Again: winpdb is crossplatform. It uses a wxwindows gui. Names are not really fortunate... I have installed the last winpdb 1.4.6 in SPE today. atb joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python unicode and Windows cmd.exe
On 14 mar, 22:22, Guillermo wrote: > > That is what happens: the file now starts with a BOM \xEB\xBB\xBF as > > you can see with a hex editor. > > Is this an enforced convention under Windows, then? My head's aching > after so much pulling at my hair, but I have the feeling that the > problem only arises when text travels through the dos console... > > Cheers, > Guillermo search for BOM in wikipedia. There it talks about notepad behavior. ja -- http://mail.python.org/mailman/listinfo/python-list
Re: Python bindings tutorial
On Mar 16, 5:20 pm, Johny wrote: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > not using os.system command. > Thanks > L. subprocess ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python bindings tutorial
On Mar 16, 5:20 pm, Johny wrote: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > not using os.system command. > Thanks > L. subprocess ? -- http://mail.python.org/mailman/listinfo/python-list
Re: to pass self or not to pass self
On Mar 17, 3:43 pm, Patrick Maupin wrote: > On Mar 17, 4:12 am, Bruno Desthuilliers > 42.desthuilli...@websiteburo.invalid> wrote: > > Patrick Maupin a écrit : > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > >> Why not create the bound methods at instantiation time, rather than > > >> using the descriptor protocol which has the overhead of creating a new > > >> bound method each time the method attribute is accessed? > > > > Well, for one thing, Python classes are open. They can be added to at > > > any time. For another thing, you might not ever use most of the > > > methods of an instance, so it would be a huge waste to create those. > > > A possible optimization would be a simple memoization on first access. > > I do agree that memoization on access is a good pattern, and I use it > frequently. I don't know if I would want the interpreter > automagically doing that for everything, though -- it would require > some thought to figure out what the overhead cost is for the things > that are only used once. > > Usually, I will have a slight naming difference for the things I want > memoized, to get the memoization code to run. For example, if you add > an underbar in front of everything you want memoized: > > class foo(object): > > def _bar(self): > pass > > def __getattr__(self, aname): > if aname.startswith('_'): > raise AttributeError > value = getattr(self, '_' + aname) > self.aname = value > return value > > obj = foo() > > So then the first time you look up obj.bar, it builds the bound > method, and on subsequent accesses it just returns the previously > bound method. > > Regards, > Pat Patrick, I was trying to understand the way your code was working but I thing I'm not getting it. I tested: from time import time class foo1(object): def _bar(self): pass def __getattr__(self, name): value = getattr(self, '_' + name) self.name = value return value class foo2(object): def bar(self): pass def a(klass, count): ins = klass() for i in xrange(count): z = ins.bar() t0 = time() a(foo1, 1000) t1 = time() a(foo2, 1000) t2 = time() print t1-t0 #75 sec print t2-t1 #11 sec foo1 is a lot slower than foo2. I understood that memoization should optimize atribute calls. Maybe I am putting my foot in my mouth... Thanks JA -- http://mail.python.org/mailman/listinfo/python-list
Re: to pass self or not to pass self
On Mar 18, 12:11 am, Patrick Maupin wrote: > On Mar 17, 5:34 pm, Joaquin Abian wrote: > > > > > On Mar 17, 3:43 pm, Patrick Maupin wrote: > > > > On Mar 17, 4:12 am, Bruno Desthuilliers > > > 42.desthuilli...@websiteburo.invalid> wrote: > > > > Patrick Maupin a écrit : > > > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > > > >> Why not create the bound methods at instantiation time, rather than > > > > >> using the descriptor protocol which has the overhead of creating a > > > > >> new > > > > >> bound method each time the method attribute is accessed? > > > > > > Well, for one thing, Python classes are open. They can be added to at > > > > > any time. For another thing, you might not ever use most of the > > > > > methods of an instance, so it would be a huge waste to create those. > > > > > A possible optimization would be a simple memoization on first access. > > > > I do agree that memoization on access is a good pattern, and I use it > > > frequently. I don't know if I would want the interpreter > > > automagically doing that for everything, though -- it would require > > > some thought to figure out what the overhead cost is for the things > > > that are only used once. > > > > Usually, I will have a slight naming difference for the things I want > > > memoized, to get the memoization code to run. For example, if you add > > > an underbar in front of everything you want memoized: > > > > class foo(object): > > > > def _bar(self): > > > pass > > > > def __getattr__(self, aname): > > > if aname.startswith('_'): > > > raise AttributeError > > > value = getattr(self, '_' + aname) > > > self.aname = value > > > return value > > > > obj = foo() > > > > So then the first time you look up obj.bar, it builds the bound > > > method, and on subsequent accesses it just returns the previously > > > bound method. > > > > Regards, > > > Pat > > > Patrick, I was trying to understand the way your code was working but > > I thing I'm not getting it. > > > I tested: > > > from time import time > > > class foo1(object): > > def _bar(self): > > pass > > def __getattr__(self, name): > > value = getattr(self, '_' + name) > > self.name = value > > return value > > > class foo2(object): > > def bar(self): > > pass > > > def a(klass, count): > > ins = klass() > > for i in xrange(count): > > z = ins.bar() > > > t0 = time() > > a(foo1, 1000) > > t1 = time() > > a(foo2, 1000) > > t2 = time() > > > print t1-t0 #75 sec > > print t2-t1 #11 sec > > > foo1 is a lot slower than foo2. I understood that memoization should > > optimize atribute calls. Maybe I am putting my foot in my mouth... > > > Thanks > > JA > > I don't think you are putting your foot in your mouth. I always have > to test to remember what works faster and what doesn't. Usually when > I memoize as I showed, it is not a simple attribute lookup, but > something that takes more work to create. As I stated in my response > to Terry, I overstated my case earlier, because of some optimizations > in len(), I think. Nonetheless, (at least on Python 2.6) I think the > advice I gave to the OP holds. One difference is that you are doing > an attribute lookup in your inner loop. I do find that performance > hit surprising, but to compare with what the OP is describing, you > either need to look up an unbound function in a dict and call it with > a parameter, or look up a bound method in a dict and call it without > the parameter. Since the dict lookup doesn't usually do anything > fancy and unexpected like attribute lookup, we pull the dict lookup > out of the equation and out of the inner loop, and just do the > comparison like this: > > >>> class foo(object): > > ... def bar(self): > ... pass > ...>>> x = foo() > > >>> def a(func, count): > > ... for i in xrange(count): > ... z=func() > ...>>> def b(func, param, count): > > ... for i in xrange(count): > ... z=func(param) > ... > > > > >>> a(x.bar, 1) # 13 seconds > >>> b(foo.bar, x, 1) # 18 seconds > > Regards, > Pat OK, Thanks. Need to play a little bit with it. Cheers JA -- http://mail.python.org/mailman/listinfo/python-list
How User-defined method objects are created?
I'm trying to understand the description of method object creation in the python 2.6 language reference (3.2. The standard type hierarchy) with little success. The points knocking me are: "User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object, an unbound user-defined method object, or a class method object. When the attribute is a user-defined method object, a new method object is only created if the class from which it is being retrieved is the same as, or a derived class of, the class stored in the original method object; otherwise, the original method object is used as it is." It is a bit of a tongue-twister for me. What the last sentence means? Please, I beg for a simple example of the different objects (user defined function, user defined method, class method) refered. Are maybe the refered objects exemplified by : #python 3.1 class Klass(): def met(self): print('method') def func(): print('function') @classmethod def kmet(klass): print('classmethod') or it is talking about another thing? What is the difference with python 3 where there is no mention to the unbound user-defined method object (same section in python 3 language reference): "User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object or a class method object." I'm trying to learn, however the task is revealing as an enormous undertaking :-) JA -- http://mail.python.org/mailman/listinfo/python-list
Re: How User-defined method objects are created?
On Mar 20, 5:39 pm, Terry Reedy wrote: > On 3/20/2010 9:54 AM, Joaquin Abian wrote: > > > > > I'm trying to understand the description of method object creation in > > the python 2.6 language reference (3.2. The standard type hierarchy) > > with little success. The points knocking me are: > > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object, an unbound user-defined method > > object, or a class method object. When the attribute is a user-defined > > method object, a new method object is only created if the class from > > which it is being retrieved is the same as, or a derived class of, the > > class stored in the original method object; otherwise, the original > > method object is used as it is." > > > It is a bit of a tongue-twister for me. What the last sentence means? > > Please, I beg for a simple example of the different objects (user > > defined function, user defined method, class method) refered. > > Are maybe the refered objects exemplified by : > > > #python 3.1 > > class Klass(): > > > def met(self): > > print('method') > > > def func(): > > print('function') > > > @classmethod > > def kmet(klass): > > print('classmethod') > > > or it is talking about another thing? > > What is the difference with python 3 where there is no mention to the > > unbound user-defined method object (same section in python 3 language > > reference): > > Python3 does not have unbound method objects. Klass.met above is just a > function.l > > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object or a class method object." > > > I'm trying to learn, however the task is revealing as an enormous > > undertaking :-) > > One can successfully use the language in the normal way without > understanding every detail of every oddball corner case. Recent 2.x is > complicated by duplication (two user object systems) and > back-compatibility constraints. Most new users do not need to bother > with obsolete complications. > > Terry Jan Reedy Terry, Right, I was just reading about this difference in 2 vs 3 in Lutz's book. Well, in fact in my case I'm not a newcomer to python (neither a professional). I have been programming for more than 4 years in python mainly medium size scientific data management applications. Currently I can write at a moderate speed and Im familiar with properties, decorators, etc. That's why it is so frustrating went I get lost in the language reference manual in a matter I wrongly though was a simple stuff. Thanks for your helpful comments. JA -- http://mail.python.org/mailman/listinfo/python-list
Re: How User-defined method objects are created?
On Mar 20, 5:24 pm, Duncan Booth wrote: > Joaquin Abian wrote: > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object, an unbound user-defined method > > object, or a class method object. When the attribute is a user-defined > > method object, a new method object is only created if the class from > > which it is being retrieved is the same as, or a derived class of, the > > class stored in the original method object; otherwise, the original > > method object is used as it is." > > > It is a bit of a tongue-twister for me. What the last sentence means? > > Please, I beg for a simple example of the different objects (user > > defined function, user defined method, class method) refered. > >>> class A(object): > > def foo(self): pass > > >>> class B(object): > > def bar(self): pass > > >>> B.baz = B.bar > >>> B.foo = A.foo > >>> instance = B() > >>> B.foo > > >>> B.bar > > >>> B.baz > > >>> instance.foo > > >>> instance.bar > > >>>> > instance.baz > > >>>> > B.__dict__['bar'] > > >>> B.__dict__['baz'] > > >>> B.__dict__['foo'] > > > > So, we have a function 'bar' stored in B's dict. When you access the > function as the attribute B.bar Python 2.x will create an unbound method > object. When you access the function through instance.bar Python creates a > bound method. Note that every time you access instance.bar it creates > another new method object: > > >>> instance.bar is instance.bar > > False > > B.baz is an unbound method stored directly in B's dict. When you access > instance.baz you get a new bound method object (it's at the same memory > location as the previous one but that's only because the lifetimes don't > overlap). Somewhat suprisingly the same also happens if you access B.baz: > it creates a new unbound method from the existing unbound method: > > >>> B.bar is B.__dict__['bar'] > > False > > B.foo is an unbound method stored directly in B's dict, but it is a method > of an A and B doesn't subclass A, so when you try to access B.foo you just > get the stored unbound method it isn't converted into a new object. Thanks Duncan, I think I got the idea. Your explanation together with the comment from Terry about the absence of unbound method objects in python 3 cleared some dust from my neuron(s) Thanks! JA -- http://mail.python.org/mailman/listinfo/python-list
Re: (a==b) ? 'Yes' : 'No'
On Mar 30, 5:40 pm, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > return (a==b) ? 'Yes' : 'No' > > My first idea is: > return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? (a==b) and 'YES' or 'NO' Yes, ugly Joaquin -- http://mail.python.org/mailman/listinfo/python-list
How many packages there are in PyPI
Hi, PyPI is reaching the 1 package figure (In the case of 3.x only about 140 packages and increasing very very slowly). Looking at available packages for 3.x I observed that some packages are listed several times. For example, lxml is listed 5 times. Are these repetitions included in the package count? If yes, just out of curiosity, somebody knows what the actual number of different packages in the PyPI reservoir is? Joaquin. -- http://mail.python.org/mailman/listinfo/python-list
Re: (a==b) ? 'Yes' : 'No'
On Mar 31, 1:18 am, Lawrence D'Oliveiro wrote: > In message <7316f3d2-bcc9-4a1a-8598- > > cdd5d41fd...@k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > > (a==b) and 'YES' or 'NO' > > > Yes, ugly > > Why would you say that’s ugly? > > By the way, you don’t need the parentheses. Lawrence, maybe it was not the perfect adjective. I meant 'not beautiful' because for me it is not an expression I can easily read. It is not internalized in my brain. I know how to use it because I learnt how to do it time ago(in Learning Python) but always I have to think how it works (like a mental translation). For me the other alternative expresion is more readable: take_it if you_have_it else search_for_it this was already in my brain before I started writing python code. Thus, I prefer this option for my code. On the other hand, in my post, I proposed the and/or style because I found interesting how symmetrical it was with the one the OP was refering: (a==b) ? 'Yes' : 'No' (a==b) and 'Yes' or 'No' I know, I could write it without parenthesis but it seems more naturally organized with it and I read it faster and clearly. I dont know exactly why but it seems also safer to me. Joaquin -- http://mail.python.org/mailman/listinfo/python-list
no module named exceptions?
In python 3.1, >>> import exceptions Traceback (most recent call last): File "", line 1, in import exceptions ImportError: No module named exceptions in 2.6 no exception is raised It should be the same in 3.1, isnt it? Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: def method with variable no of parameters file.writeStuff(n, a1, a2, ...an)
On Apr 2, 1:25 pm, "vlad_fig" wrote: > Hello all, > > I would like some help with setting up a method that would allow me to change > its number of parameters. For example: > > #- > class createfile(object): > > def __init__(self, > modelName = None, > someLines = None): > > self.modelName = modelName > > if someLines is None: > self.someLines = [] > else: > self.someLines = someLines > > def writeStuff(self, > numberParameters = None, > Parameter1 = None,... ??? ) > self.someLines .append("yes, we can %s" % self.Parameter1) > #- > file = createfile('file') > > file.writeStuff(2,a1,a2) > file.writeStuff(3,a1,a2,a3) > > file.writeStuff(n,a1,a2,...an) > > --- > so i want a method i can call based on the number of parameters n , and that > allows me to add these extra parameters based on n > > Thank you, > Vicnic Maybe you are looking for *args: class Test(): def meth(self, *args): print args inst = Test() inst.meth(1,2,3,4,5,6,7) #prints (1,2,3,4,5,6,7) Cheers Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: Simplify Python
On Apr 6, 9:04 pm, ja1lbr3ak wrote: > I'm trying to teach myself Python, and so have been simplifying a > calculator program that I wrote. The original was 77 lines for the > same functionality. Problem is, I've hit a wall. Can anyone help? > > loop = input("Enter 1 for the calculator, 2 for the Fibonacci > sequence, or something else to quit: ") > while loop < 3 and loop > 0: > if loop == 1: > print input("\nPut in an equation: ") > if loop == 2: > a, b, n = 1, 1, (input("\nWhat Fibonacci number do you want to > go to? ")) > while n > 0: > print a > a, b, n = b, a+b, n-1 > loop = input("\nEnter 1 for the calculator, 2 for the Fibonacci > sequence, or something else to quit: ") You could structure it a bit better but something to start with could be(it works): def calc(n): print n def fibo(n): a=b=1 while n > 0: print a a, b, n = b, a+b, n-1 NOTE = """Enter 1 for the calculator, 2 for the Fibonacci sequence, or something else to quit: """ while True: loop = raw_input(NOTE) if loop == '1': forcalc = raw_input("\nPut in an equation: ") calc(forcalc) elif loop == '2': forfibo = raw_input("\nWhat Fibonacci number do you want to go to? ") n = int(forfibo) fibo(n) else: break Cheers Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: Simplify Python
On Apr 6, 11:04 pm, ja1lbr3ak wrote: > On Apr 6, 4:56 pm, Joaquin Abian wrote: > > > > > On Apr 6, 9:04 pm, ja1lbr3ak wrote: > > > > I'm trying to teach myself Python, and so have been simplifying a > > > calculator program that I wrote. The original was 77 lines for the > > > same functionality. Problem is, I've hit a wall. Can anyone help? > > > > loop = input("Enter 1 for the calculator, 2 for the Fibonacci > > > sequence, or something else to quit: ") > > > while loop < 3 and loop > 0: > > > if loop == 1: > > > print input("\nPut in an equation: ") > > > if loop == 2: > > > a, b, n = 1, 1, (input("\nWhat Fibonacci number do you want to > > > go to? ")) > > > while n > 0: > > > print a > > > a, b, n = b, a+b, n-1 > > > loop = input("\nEnter 1 for the calculator, 2 for the Fibonacci > > > sequence, or something else to quit: ") > > > You could structure it a bit better but something to start with could > > be(it works): > > > def calc(n): > > print n > > > def fibo(n): > > a=b=1 > > while n > 0: > > print a > > a, b, n = b, a+b, n-1 > > > NOTE = """Enter 1 for the calculator, 2 for the Fibonacci > > sequence, or something else to quit: """ > > > while True: > > > loop = raw_input(NOTE) > > > if loop == '1': > > forcalc = raw_input("\nPut in an equation: ") > > calc(forcalc) > > elif loop == '2': > > forfibo = raw_input("\nWhat Fibonacci number do you want to go > > to? ") > > n = int(forfibo) > > fibo(n) > > else: > > break > > > Cheers > > Joaquin > > Actually, when I tried yours the calculator just spits out the input > again, which is why I used input instead of raw_input. I see. input evaluates your input string while raw_input just yields the string as a string. I tried to encapsulate the calculator in the function calc in order for you to implement the logic, making no assumption about how the calculator should work. If what you actually want to do is to evaluate strings containing valid python code you can either use input for the 'Put in an equation' line or better modify function calc to do the job: def calc(n): print eval(n) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why these don't work??
On Apr 8, 10:08 pm, "M. Hamed" wrote: > Thanks All. That clears alot of confusion. It seems I assumed that > everything that works for lists works for strings (the immutable vs > mutable hasn't sunken in yet). > > On the other hand (other than installing NumPy) is there a built-in > way to do an array full of zeros or one just like the numpy.zeros()? I > know I can do it with list comprehension (like [0 for i in > range(0,20)] but these are too many keystrokes for python :) I was > wondering if there is a simpler way. > > I had another question about arrays but I should probably start > another thread. > > Regards, > > On Apr 8, 11:43 am, MRAB wrote: > > > M. Hamed wrote: > > > I'm trying the following statements that I found here and there on > > > Google, but none of them works on my Python 2.5, are they too old? or > > > newer? > > > > "abc".reverse() > > > Lists have a .reverse() method which reverses the list elements > > in-place, but strings don't because they're immutable. > > > There's a built-in function reversed() which returns an iterator over an > > iterable object, eg a string: > > > print reversed("abc") > > > for c in reversed("abc"): > > print c > > > It's all in the documentation. > > > > import numpy > > > numpy isn't part of the standard library; you'd need to download and > > install it. > > if you want an array you can get it from module array >> import array >> array.array('i', [0]*100) array('i', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) if you want simply a list: >> [0] * 100 yields a list of hundred zeros cheers joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list reordering
On Apr 9, 12:52 am, Ben Racine wrote: > I have a list... > > ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', > 'dir_330_error.dat'] > > I want to sort it based upon the numerical value only. > > Does someone have an elegant solution to this? > > Thanks, > Ben R. not sure about elegance, but my two cents: >> mylist = ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', >> 'dir_330_error.dat'] >> mylist = [(int(item.split('_')[1]), item) for item in mylist] >> mylist.sort() >> mylist = [item for idx, item in mylist] >> mylist ['dir_0_error.dat', 'dir_30_error.dat', 'dir_120_error.dat', 'dir_330_error.dat'] joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic list reordering
On Apr 9, 1:58 am, Chris Rebert wrote: > On Thu, Apr 8, 2010 at 4:01 PM, Joaquin Abian wrote: > > On Apr 9, 12:52 am, Ben Racine wrote: > >> I have a list... > > >> ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', > >> 'dir_330_error.dat'] > > >> I want to sort it based upon the numerical value only. > > >> Does someone have an elegant solution to this? > > > not sure about elegance, but my two cents: > > >>> mylist = ['dir_0_error.dat', 'dir_120_error.dat', 'dir_30_error.dat', > >>> 'dir_330_error.dat'] > >>> mylist = [(int(item.split('_')[1]), item) for item in mylist] > >>> mylist.sort() > >>> mylist = [item for idx, item in mylist] > >>> mylist > > > ['dir_0_error.dat', 'dir_30_error.dat', 'dir_120_error.dat', > > 'dir_330_error.dat'] > > At least conceptually, that's how list.sort() with a key= argument > works internally (i.e. via Schwartzian transform). > > Cheers, > Chris > --http://blog.rebertia.com Chris, thanks for the comment. I did not know that name (Schwartzian transform) I knew it as the decorate-sort-undecorate strategy. Now after learning that it was a Perl idiom I feel somewhat embarrassed ;-) BTW, I actually prefer the l.sort(key=f) method. Just my lazy neurons were back to Python 2.3 when I wrote the response. Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.7 beta 1
On Apr 11, 6:53 pm, Steven D'Aprano wrote: > > In any case, IDLE is one IDE out of many, and not really up to > professional quality -- it's clunky and ugly. It isn't Python, it is a > tool written in Python. > > -- > Steven But this is a tool that is a part of the python distribution and often recommended to python beginners as their first IDE. So IDLE is responsible for the first impression on Python to many. If IDLE is considered as of low quality and ugly, after so many years, why it is not fixed or replaced?. I'm just wondering. joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: packaging multiple python scripts as Windows exe file
On Apr 13, 9:56 pm, Mike Driscoll wrote: > On Apr 12, 5:20 pm, Alex Hall wrote: > > > > > Hi all, > > While my project is still suffering from major import problems, I will > > soon have to try to package it as a Windows executable file. I do not > > want an installer; I want the user to be able to run the program for > > as long as they want, then to quit (by using a command from inside the > > program) and that is it. Nothing to install, no files to copy, no > > registry editing, just start and use it until done. > > > I know about the popular solutions for this sort of thing, but I read > > that a DLL is required, and that this dll cannot be (legally) > > distributed by myself? A few questions here: > > 1. Did I read this wrong / is this outdated? Please answer 'yes' as > > this will be a real pain to deal with. > > > 2. If I must have it but can distribute it, where should it go so my > > program can find it? > > > 3. If the user must download it for legal reasons, instead of me > > giving it to them, can I just have a Python script take care of it and > > put it in the same directory as the program, so the program can find > > it, or do I need to register the dll with the system? If I need to > > register, does this require admin login? > > > Thanks as always! > > > -- > > Have a great day, > > Alex (msg sent from GMail website) > > mehg...@gmail.com;http://www.facebook.com/mehgcap > > Without knowing the exact DLL you're thinking of, we can't be sure > what the answer is. But I think you're talking about a certain MS DLL > that Python distributes. If so, I've read multiple threads on this > topic that claim that since Python distributes it, there is an implied > permission that you can as well. Since I'm not a lawyer, I can't say > for sure, but the articles I've seen are pretty convincing. > > --- > Mike Driscoll > > Blog: http://blog.pythonlibrary.org the OP probably means MSVCR71.dll that is needed to make single file executables with py2exe. This has been discussed elsewhere. Look at http://www.py2exe.org/index.cgi/Tutorial#Step5 joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe and msvcp90.dll
On Apr 15, 6:19 am, Alex Hall wrote: > Hi all, > I am still fighting with py2exe; I keep getting "error: msvcp90.dll: > no such file or directory" right after it says it is searching for > required dlls. I have followed the py2exe tutorial, though, and I am > not sure why it is not finding the dlls, which are in both > c:\windows\system32 and in mainFolder/dlls, where mainFolder is the > main folder of my project, containing setup.py. Here is my setup file: > > from distutils.core import setup > import py2exe > from glob import glob > data_files=[("Microsoft.VC90.CRT", glob(r'c:\arm\dlls\*.*'))] > setup(data_files=data_files, console=['main.pyw']) > > Of course, the location to glob is hard-coded. Also, I do not intend > this to have any console. Can I just omit the console argument? I > leave it in for now since the tutorial seems to indicate that such a > file is necessary, but I do not want to have one eventually. Thanks in > advance, as always! Oh, the entire source is > athttp://www.gateway2somewhere.com/sw/sw.zip > as it usually is (and this time, I tested the link!). > > -- > Have a great day, > Alex (msg sent from GMail website) > mehg...@gmail.com;http://www.facebook.com/mehgcap Did you already checked http://stackoverflow.com/questions/323424/py2exe-fails-to-generate-an-executable and the links there?. I am a heavy user of py2exe in winxp with python2.5. It works great producing single executables with matplotlib, wxpython, and others. Please report if you get your problem fixed. Sure will be helpful for everybody Luck Joaquin -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy error undefined symbol: lsame_
On Apr 19, 7:15 pm, gerardob wrote: > I installed scipy (and all the required libraries) and the following error > appears when i tried run a simple example which uses the optimize package of > scipy. I tried also numpy alone and it works ( at least for printing > numpy.array([10,20,10])) > > error: > > Traceback (most recent call last): > File "main_test.py", line 2, in > from scipy import optimize > File > "/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/__init__.py", > line 11, in > from lbfgsb import fmin_l_bfgs_b > File > "/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/lbfgsb.py", > line 30, in > import _lbfgsb > ImportError: > /home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/_lbfgsb.so: > undefined symbol: lsame_ > gberbeg...@actarus:~/python/mycodes> > > Any ideas on how to solve this problem? Thanks. > > PS: the example is below: > > import numpy > from scipy import optimize > > a = numpy.array([10,20,10]) > print a > > def f_(x): > return x*x > > x,f,d = optimize.fmin_l_bfgs_b(f_,[0.1],fprime=None, approx_grad = True, > bounds = [(-1,1)], iprint=30, maxfun=15) > > -- > View this message in > context:http://old.nabble.com/scipy-error-undefined-symbol%3A-lsame_-tp282877... > Sent from the Python - python-list mailing list archive at Nabble.com. Um... The snip works perfect on my computer. Just copy and paste. What libraries are you talking about you had to download? Are you on windows or linux? On windows you dont need to download anything but numpy and scipy packages. joaquin -- http://mail.python.org/mailman/listinfo/python-list