Re: ISO module for binomial coefficients, etc.
Maybe this could be of interest : http://tnt.math.metro-u.ac.jp/nzmath/manual/modules/combinatorial.html hope this helps Id -- http://mail.python.org/mailman/listinfo/python-list
How to Embed PHP in HTML print
I am running a Python application under apache web server, executing as a cgi script. Most of the output is print statements that write HTML. I'd like to embed some PHP code within the HTML. The PHP is a gallery plugin script that talks to the core photo gallery application, written in php. The idea is that my python app can display a random image from a photo album, using the photo gallery application's plugin script. If I do: 'print ?php ... ?', it doesn't work. I imagine because the web server never sees it as php code. Is there a way to do this? Some possible ideas: Is there a way I can get python to call functions within a PHP app? Perhaps write the plugin in a separate script in PHP, and include that page within my output so that apache recognises the page inclusion? How to get apache to pay attention to the output so it wakes up and does some server-side includes? Many thanks for any help. -- NickC -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils not finding all of my pure python modules
En Thu, 21 Jan 2010 12:41:20 -0300, Jeremy jlcon...@gmail.com escribió: from distutils.core import setup purePythonModules = ['regex', 'gnuFile'] setup(name='PythonForSafeguards', version='0.9.1', description = 'Python code for MCNP and Safeguards analysis.', author = 'Jake the Snake', author_email = 'someth...@blah.com', packages = ['MCNP', 'Safeguards'], url='http://lanl.gov', py_modules = purePythonModules, ) # = Everythin seems to work fine except the gnuFile.py script does not get put into the distribution. I know the file exists in the same directory as regex.py and has the same permissions. regex.py and gnuFile.py must be in the same directory as setup.py, ok? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Jan 23, 8:00 pm, Raymond Hettinger pyt...@rcn.com wrote: [Steve Howell] Why wouldn't you get a competent C programmer simply make list_ass_slice smart enough to make list.pop(0) O(1)? When this suggestion was discussed on python-dev years ago, it was rejected. One reason is that it was somewhat common for C code to access the list data structure directly (bypassing API accessor functions). Changing the list to have a starting offset would break existing C extensions. Another reason is that Guido is non-tolerant of space or time trade-offs for lists and tuples because they pervade the language and are heavily used internally. Any additional space or time requirement however small would impact the language performance as a whole. FWIW, that is also the reason that lists are not weak-referenceable (it would cost one extra pointer field per instance and that wasn't deemed to be worth it). The brilliant computer scientist, Christian Heimes, provides the answers, and I am paraphrasing here, of course: IMHO, Christian IS a brilliant computer scientist, so I'll ignore the rude intention and take the sentence literally. You are also a brilliant computer scientist, despite the fact that you are defending a list implemenation that can't pop the first element off the list in O(1) time. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Embed PHP in HTML print
NickC reply...@works.fine.invalid wrote: Some possible ideas: Is there a way I can get python to call functions within a PHP app? Perhaps write the plugin in a separate script in PHP, and include that page within my output so that apache recognises the page inclusion? How to get apache to pay attention to the output so it wakes up and does some server-side includes? One option would be to ditch either the Python or the PHP and do everything in one language. Probably your simplest option is to get the web server to generate the PHP output separately. Since it's the same web server you can just use some javascript in the final web page to call in the PHP generated content with ajax. Alternatively, use urllib in Python to retrieve a page from the Apache server and insert that into its own output: that way you won't requrie javascript in the client, but that might be messy if you have authentication or sessions going on. -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Sun, 24 Jan 2010 02:33:36 -0800, Steve Howell wrote: You are also a brilliant computer scientist, despite the fact that you are defending a list implemenation that can't pop the first element off the list in O(1) time. You say that like it's a bad thing. It's very simple: the trade-offs that the Python development team have deliberately chosen aren't the same trade-offs that you prefer. That doesn't make your trade-offs right and Python's wrong. They're just different, and if Python lists had your preferred implementation, I guarantee that somebody would be complaining about it right now. If you're serious about wanting O(1) pops from the start of the list, write your own list implementation and use it. You might even like to make it public, so others can use it as well. But please stop with the snide remarks and poorly disguised insults and back-handed compliments, it's getting tedious. Or just change your algorithm slightly -- it's not hard to turn an algorithm that pops from the start of a list to one that pops from the end of the list. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe deal with python command line inside a program
On Jan 22, 7:35 pm, susan_kij...@yahoo.ca wrote: Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Python25\\python.exe'', how can I make this work in executable package through py2exe? I have to fix the following problems: -Source code shouldn't exposed in an executable program -Since python environment is not required when running an executable program, how to deal with the situation that C:\\Python25\ \python.exe is required as part of command? Thanks in advance! Hi. What does it do when you try to execute it with py2exe? Does it fail to run? What is the error? -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe deal with python command line inside a program
On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley tart...@tartley.com wrote: On Jan 22, 7:35 pm, susan_kij...@yahoo.ca wrote: Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Python25\\python.exe'', how can I make this work in executable package through py2exe? I have to fix the following problems: -Source code shouldn't exposed in an executable program -Since python environment is not required when running an executable program, how to deal with the situation that C:\\Python25\ \python.exe is required as part of command? Thanks in advance! Hi. What does it do when you try to execute it with py2exe? Does it fail to run? What is the error? The subprocess call would fail utterly since sys.executable is apparently inaccurate for py2exe-generated executables. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ISC License
On 23 ene, 18:45, a...@pythoncraft.com (Aahz) wrote: In article 00eb248d-c9c9-430f-bc83-41ac865c5...@e11g2000yqe.googlegroups.com, Joan Miller pelok...@gmail.com wrote: There is a license approved by the OSI, the ISC License [1], which should be included in the PyPi classifiers [2]. [1]https://www.isc.org/software/license http://www.opensource.org/licenses/isc-license.txt [2]http://pypi.python.org/pypi?%3Aaction=list_classifiers http://pypi.python.org/pypihas a link named Bug Reports -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ import antigravity Added! http://sourceforge.net/tracker/?func=detailaid=2938526group_id=66150atid=513503 -- http://mail.python.org/mailman/listinfo/python-list
Re: iterating lists
Steven D'Aprano, 23.01.2010 18:44: On Sat, 23 Jan 2010 18:29:33 +0100, Roel Schroeven wrote: for w in l1[:]: #use copy of l1 for iteration print(l1.pop()) #decomposite list I would prefer: while l1: print(l1.pop()) I would prefer: for x in reversed(l1): print(x) l1[:] = [] And garbage dispose of the entire list in one go, instead of an item at a time. IIRC, that's what CPython does anyway, so no need to make this more complex than necessary. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO module for binomial coefficients, etc.
kj wrote: Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorials (on the order of 1!), using floating-point approximations as needed, and is smart about optimizations, memoizations, etc. TIA! ~K You do realize that a standard. python floating point number cannot possibly approximate a number like 1! Better use longs. I'd check out the gamma function, which matches factorial for integer arguments (plus or minus 1). DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO module for binomial coefficients, etc.
* Dave Angel: kj wrote: Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorials (on the order of 1!), using floating-point approximations as needed, and is smart about optimizations, memoizations, etc. TIA! ~K You do realize that a standard. python floating point number cannot possibly approximate a number like 1! I think what kj is looking for, provided she/he is knowledgable about the subject, is code that does something like from math import * log_fac = 0 for i in range( 1, 1+1 ): ... log_fac += log( i, 10 ) ... print( 1! = {}e{}.format( 10**(log_fac % 1), int( log_fac ) ) ) 1! = 2.84625968062e35659 _ which turned out to be accurate to 10 digits. Better use longs. That would involve incredible overhead. E.g., how many bytes for the number above? Those bytes translate into arithmetic overhead. I'd check out the gamma function, which matches factorial for integer arguments (plus or minus 1). Or, e.g., logarithms... ;-) Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Embed PHP in HTML print
On Sun, 24 Jan 2010 10:37:51 +, Duncan Booth wrote: content with ajax. Alternatively, use urllib in Python to retrieve a page from the Apache server and insert that into its own output: that Thanks for hint on urllib. I shake my head in amazement with python sometimes. I'll write it here: print urllib.urlopen('http://myserver.com/phpscript.php').read() That's it. *One* line. The output from the php script is: a href='zenphoto/kitty/IMG_0759.jpg' title='Random Picture...' img src='zenphoto/cache/kitty/IMG_0759_800.jpg' alt=random image IMG_0759 //a and the one-liner seamlessly prints that to insert it into the html output. And I thought it would be hard; I should have known better. -- NickC -- http://mail.python.org/mailman/listinfo/python-list
ctypes for AIX
I need to use ctypes with python running on AIX. It appears that python is being developed mostly for windows. Is there a policy concerning getting functions like ctypes working on AIX. Jim Waddle KIT-D 425-785-5194 -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes for AIX
On Sun, Jan 24, 2010 at 5:54 AM, Waddle, Jim jim.wad...@boeing.com wrote: I need to use ctypes with python running on AIX. According to the ctypes readme, ctypes is based on libffi, which according to its website, supports AIX for PowerPC64. So, perhaps you could state what the actual error or problem you're encountering is? It is theoretically possible the ctypes-bundled libffi is either outdated or had the AIX-specific bits removed; I don't know, I'm not a CPython dev. It appears that python is being developed mostly for windows. No, not really; your statement is especially ironic considering one of Python's primary areas of use is for web applications as part of a LAMP stack. Is there a policy concerning getting functions like ctypes working on AIX. No idea. Someone will probably chime in though. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Default path for files
Hi all, can anybody tell me whether there's a way to change the default location for files to be opened by open()? I'd like to be able to create files somewhere other than my Python folder without having to write the full path in the filename every time. Sorry if this is a stupid question, I don't know much about programming. -- http://mail.python.org/mailman/listinfo/python-list
Re: Default path for files
On Sun, Jan 24, 2010 at 4:08 PM, Rotwang sg...@hotmail.co.uk wrote: Hi all, can anybody tell me whether there's a way to change the default location for files to be opened by open()? I'd like to be able to create files somewhere other than my Python folder without having to write the full path in the filename every time. Sorry if this is a stupid question, I don't know much about programming. Check out http://docs.python.org/library/os.html and the function chdir it is what you are looking for. -- http://mail.python.org/mailman/listinfo/python-list
how to list the attributes of a class, not an object?
once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? eg., i was playing with dicts and noticed that the type returned by the keys() method was dict_keys. so i'm now curious as to the attributes of the dict_keys class. but i don't know how to look at that without first *creating* such an instance, then asking for dir(dk). surely there's a simpler way just using the class name, no? rday p.s. any recommendations for the most concise reference sheet for python 3 that exists? being able to print off the entire language spec on two or four pages and tacking it up in front of me would be just ducky. thanks. -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
some turtle questions
Hello, I am trying to think of things to do with the turtle module with my students, and I have some ideas where I am not sure whether the turtle module can do it. 1) is there a way to determine the current screen pixel color? I am thinking about having the turtle go forward until it reaches an object, say a red circle. I can probably do this by making circle objects (drawn with turtles themselves) which know their own position, and check against this info. But I thought it might be useful also for the turtle to know. 2) is there a way to put a limit on the extent the turtle can travel? it seems I can keep moving off of the screen. Is there a way to make it so that a forward(50) command, at the edge, either raises an exception (at the wall) or simply doesn't move the turtle because of the limit? thanks! bb -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
Dnia 23-01-2010 o 15:19:56 Peter Otten __pete...@web.de napisał(a): def consume_islice(n, items): next(islice(items, n, n), None) One problem: the above function doesn't consume the entire iterator like the original example does for n=None. Passing sys.maxint instead is not pretty. Not very pretty, but noticeably (though not dramatically) faster for n=None. Consider a modified version of the script from http://bugs.python.org/issue7764: import collections, sys from itertools import islice, repeat def consume0(iterator, n): # the old one collections.deque(islice(iterator, n), maxlen=0) def consume1(iterator, n): # similar to the primary proposal if n is None: collections.deque(iterator, maxlen=0) elif n != 0: next(islice(iterator, n-1, None), None) def consume2(iterator, n): # the approved proposal (see #7764) if n is None: collections.deque(iterator, maxlen=0) else: next(islice(iterator, n, n), None) def consume3(iterator, n): # with sys.maxint if n is None: n = sys.maxint # (maybe should be sys.maxsize instead?) next(islice(iterator, n, n), None) def test(fs): for consume in fs: iterator = iter(range(10)) consume(iterator, 3) rest = list(iterator) assert rest == range(3, 10), consume.__name__ iterator = iter(range(10)) consume(iterator, 0) rest = list(iterator) assert rest == range(10), consume.__name__ iterator = iter(range(10)) consume(iterator, None) rest = list(iterator) assert rest == [], consume.__name__ if __name__ == __main__: from timeit import Timer fs = (consume0, consume1, consume2, consume3) test(fs) iterator = repeat(None, 1000) for consume in fs: print consume.__name__ for n in (10, 100, 1000, None): print %6s: % n, print Timer(consume(iterator, %s) % n, import collections, sys\n from __main__ import consume, iterator).timeit() print Results [Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 pentium4 2.4 GHz]: consume0 10: 2.94313001633 100: 2.91833305359 1000: 2.93242096901 None: 2.90090417862 consume1 10: 1.80793309212 100: 1.7936270237 1000: 1.83439803123 None: 2.37652015686 consume2 10: 1.58784389496 100: 1.5890610218 1000: 1.58557391167 None: 2.37005710602 consume3 10: 1.6071870327 100: 1.61109304428 1000: 1.60717701912 None: 1.81885385513 Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Default path for files
Krister Svanlund wrote: On Sun, Jan 24, 2010 at 4:08 PM, Rotwang sg...@hotmail.co.uk wrote: Hi all, can anybody tell me whether there's a way to change the default location for files to be opened by open()? I'd like to be able to create files somewhere other than my Python folder without having to write the full path in the filename every time. Sorry if this is a stupid question, I don't know much about programming. Check out http://docs.python.org/library/os.html and the function chdir it is what you are looking for. Thank you. So would adding import os os.chdir(path) to site.py (or any other module which is automatically imported during initialisation) change the default location to path every time I used Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to list the attributes of a class, not an object?
* Robert P. J. Day: once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? eg., i was playing with dicts and noticed that the type returned by the keys() method was dict_keys. so i'm now curious as to the attributes of the dict_keys class. but i don't know how to look at that without first *creating* such an instance, then asking for dir(dk). Like, dir( list ) where 'list' is the built-in type. There's a pretty-printer for that somewhere, but I can't recall. And as I also recommended in your thread examining an initial, pristine python3 shell session, help( list ) or more generally help( list ) surely there's a simpler way just using the class name, no? Yes. :-) rday p.s. any recommendations for the most concise reference sheet for python 3 that exists? being able to print off the entire language spec on two or four pages and tacking it up in front of me would be just ducky. thanks. Sorry, don't know. Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: how to list the attributes of a class, not an object?
24-01-2010, 16:28:26 Robert P. J. Day rpj...@crashcourse.ca wrote once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? dir(type(an_obj)) or more reliable: list(vars(type(an_obj))) (dir() uses __dir__ which can be implemented in any way, and default implementation, accordinto to the docs, attempts to produce the most relevant, rather than complete, information). eg., i was playing with dicts and noticed that the type returned by the keys() method was dict_keys. so i'm now curious as to the attributes of the dict_keys class. but i don't know how to look at that without first *creating* such an instance, then asking for dir(dk). Why you bother about creating an instance? Just do it: list(vars(type({}.keys( or dir(type({}.keys())) if dir() satisfies you. Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Default path for files
Rotwang wrote: import os os.chdir(path) to site.py (or any other module which is automatically imported during initialisation) change the default location to path every time I used Python? First of all you shouldn't alter the site module ever! The optional sitecustomize module exists to make global changes. A library must never change the current working directory. It's up to the application to choose the right working directory. If you mess with the working directory in a library or global module like site you *will* break applications. Python has multiple ways to modify the list of importable locations, either globally, for the current user or the current application. Use them wisely! Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: how to list the attributes of a class, not an object?
On Sun, 24 Jan 2010, Alf P. Steinbach wrote: * Robert P. J. Day: once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? eg., i was playing with dicts and noticed that the type returned by the keys() method was dict_keys. so i'm now curious as to the attributes of the dict_keys class. but i don't know how to look at that without first *creating* such an instance, then asking for dir(dk). Like, dir( list ) where 'list' is the built-in type. There's a pretty-printer for that somewhere, but I can't recall. except that doesn't work for dir(dict_keys) so what's the difference there? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
Jan Kaliszewski wrote: Dnia 23-01-2010 o 15:19:56 Peter Otten __pete...@web.de napisał(a): def consume_islice(n, items): next(islice(items, n, n), None) One problem: the above function doesn't consume the entire iterator like the original example does for n=None. Passing sys.maxint instead is not pretty. Not very pretty, but noticeably (though not dramatically) faster for n=None. Consider a modified version of the script from http://bugs.python.org/issue7764: import collections, sys from itertools import islice, repeat def consume0(iterator, n): # the old one collections.deque(islice(iterator, n), maxlen=0) def consume1(iterator, n): # similar to the primary proposal if n is None: collections.deque(iterator, maxlen=0) elif n != 0: next(islice(iterator, n-1, None), None) def consume2(iterator, n): # the approved proposal (see #7764) if n is None: collections.deque(iterator, maxlen=0) else: next(islice(iterator, n, n), None) def consume3(iterator, n): # with sys.maxint if n is None: n = sys.maxint # (maybe should be sys.maxsize instead?) next(islice(iterator, n, n), None) def test(fs): for consume in fs: iterator = iter(range(10)) consume(iterator, 3) rest = list(iterator) assert rest == range(3, 10), consume.__name__ iterator = iter(range(10)) consume(iterator, 0) rest = list(iterator) assert rest == range(10), consume.__name__ iterator = iter(range(10)) consume(iterator, None) rest = list(iterator) assert rest == [], consume.__name__ if __name__ == __main__: from timeit import Timer fs = (consume0, consume1, consume2, consume3) test(fs) iterator = repeat(None, 1000) for consume in fs: print consume.__name__ for n in (10, 100, 1000, None): print %6s: % n, print Timer(consume(iterator, %s) % n, import collections, sys\n from __main__ import consume, iterator).timeit() print Results [Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 pentium4 2.4 GHz]: consume0 10: 2.94313001633 100: 2.91833305359 1000: 2.93242096901 None: 2.90090417862 consume1 10: 1.80793309212 100: 1.7936270237 1000: 1.83439803123 None: 2.37652015686 consume2 10: 1.58784389496 100: 1.5890610218 1000: 1.58557391167 None: 2.37005710602 consume3 10: 1.6071870327 100: 1.61109304428 1000: 1.60717701912 None: 1.81885385513 Regards, *j Don't the results look suspicious to you? Try measuring with iterator = iter([]) I'm sure you'll get the same result. An easy fix which introduces some constant overhead but keeps the results comparable: for consume in fs: print consume.__name__ for n in (10, 100, 1000, None): print %6s: % n, print Timer(consume(repeat(None, 1000), %s) % n, import collections, sys\n from __main__ import consume, repeat).timeit() print Just for fun, here's a variant of consume3 for the paranoid: _sentinel = object() def consume4(iterator, n): if n is None: n = sys.maxint while next(islice(iterator, n, n), _sentinel) is not _sentinel: pass Peter -- http://mail.python.org/mailman/listinfo/python-list
PS.
24-01-2010, 16:56:42 Jan Kaliszewski z...@chopin.edu.pl wrote: 24-01-2010, 16:28:26 Robert P. J. Day rpj...@crashcourse.ca wrote once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? dir(type(an_obj)) or more reliable: list(vars(type(an_obj))) (dir() uses __dir__ which can be implemented in any way, and default implementation, accordinto to the docs, attempts to produce the most relevant, rather than complete, information). I missed one important thing: * dir(a_type) mostly applies to attributes of a_type *and* of its base types/classes [1]. * vars() applies only to attributes of this particular type (AFAIN vars(sth) and sth.__dict__ are practically the same). Example: class D(dict): pass ... dir(D) ['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'] list(vars(D)) ['__dict__', '__module__', '__weakref__', '__doc__'] Regards, *j [1] In Python 3.x *type* and *class* is practically the same. (though built-in ones are denoted as *types* rather than *classes* -- using this naming convention a *class* is simply a user-defined *type*). -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Default path for files
Christian Heimes wrote: Rotwang wrote: import os os.chdir(path) to site.py (or any other module which is automatically imported during initialisation) change the default location to path every time I used Python? First of all you shouldn't alter the site module ever! The optional sitecustomize module exists to make global changes. A library must never change the current working directory. It's up to the application to choose the right working directory. If you mess with the working directory in a library or global module like site you *will* break applications. Python has multiple ways to modify the list of importable locations, either globally, for the current user or the current application. Use them wisely! Christian OK, thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to list the attributes of a class, not an object?
* Robert P. J. Day: On Sun, 24 Jan 2010, Alf P. Steinbach wrote: * Robert P. J. Day: once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? eg., i was playing with dicts and noticed that the type returned by the keys() method was dict_keys. so i'm now curious as to the attributes of the dict_keys class. but i don't know how to look at that without first *creating* such an instance, then asking for dir(dk). Like, dir( list ) where 'list' is the built-in type. There's a pretty-printer for that somewhere, but I can't recall. except that doesn't work for dir(dict_keys) so what's the difference there? 'list' is a built-in type that by default is available. 'dict_keys' is a type that you're not meant to use directly, so it's not made available by default. The 'type' function yields the type of its argument, so you *can* do e.g. DictKeys = type( {}.keys() ) dir( DictKeys ) list( vars( DictKeys ) ) help( DictKeys ) It doesn't help much though because the only method of interrest is __iter__, which produces an iterator that you can use e.g. in a for loop or to construct a list, whatever. The relevant place to find out more about keys() is in the documentation. Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
Don't the results look suspicious to you? Try measuring with iterator = iter([]) You are obviously right, my brain doesn't work well today :-( But the corret results even more distinctly support my thesis -- that for n=None using n=sys.maxint (consume3) is noticeably faster than 0-maxlen deque (consume1 and consume2): consume0 10: 4.06217813492 100: 8.45529103279 1000: 53.237226963 None: 54.0063519478 consume1 10: 2.59927105904 100: 3.47109603882 1000: 12.7196500301 None: 26.0995740891 consume2 10: 2.36225390434 100: 3.22979712486 1000: 12.5794699192 None: 28.5096430779 consume3 10: 2.39173388481 100: 3.43043398857 1000: 14.3361399174 None: 14.8560190201 Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list
Re: how to list the attributes of a class, not an object?
24-01-2010, 17:37:41 Alf P. Steinbach al...@start.no wrote: DictKeys = type( {}.keys() ) dir( DictKeys ) list( vars( DictKeys ) ) help( DictKeys ) It doesn't help much though because the only method of interrest is __iter__ Not only. Please, consider: dictkeys = type({}.keys()) set(dir(dictkeys)).difference(dir(object)) {'__ror__', '__rsub__', '__and__', '__rand__', '__contains__', '__len__', '__iter__', '__or__', '__rxor__', '__xor__', '__sub__'} And e.g. comparision-related mehods (__gt__, __le__ and so on) also are more interensing in dict keys views than in plain object() instances... Regards, *j -- http://mail.python.org/mailman/listinfo/python-list
Re: Symbols as parameters?
En Fri, 22 Jan 2010 10:16:50 -0300, Alf P. Steinbach al...@start.no escribió: I get the impression that there's some message traffic that I don't see, perhaps on the mailing list, since (a) I haven't seen that about 'locals' pointed out by anyone else in this thread, and I think I've read all messages in the thread, and (b) sometimes threads pop up that start with a reply. For example, the recent thread Covert number into string started with a /reply/ in my newreader, using EternalSeptember's NNTP host. It also starts with a reply in Google's archives, url: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b8097d4de4a9c9b0/cb3a2e6ccd7736ef. gmane (news.gmane.org) is a newsserver that acts as a bridge news - mailing lists. The post that started the thread you mention is available there, as well as those previous posts in this thread about the danger of using locals() -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Splitting text at whitespace but keeping the whitespace in the returned list
I need to parse some ASCII text into 'word' sized chunks of text AND collect the whitespace that seperates the split items. By 'word' I mean any string of characters seperated by whitespace (newlines, carriage returns, tabs, spaces, soft-spaces, etc). This means that my split text can contain punctuation and numbers - just not whitespace. The split( None ) method works fine for returning the word sized chunks of text, but destroys the whitespace separators that I need. Is there a variation of split() that returns delimiters as well as tokens? Thank you, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting text at whitespace but keeping the whitespace in the returned list
pyt...@bdurham.com wrote: I need to parse some ASCII text into 'word' sized chunks of text AND collect the whitespace that seperates the split items. By 'word' I mean any string of characters seperated by whitespace (newlines, carriage returns, tabs, spaces, soft-spaces, etc). This means that my split text can contain punctuation and numbers - just not whitespace. The split( None ) method works fine for returning the word sized chunks of text, but destroys the whitespace separators that I need. Is there a variation of split() that returns delimiters as well as tokens? I'd use the re module: import re re.split(r'(\s+)', Hello world!) ['Hello', ' ', 'world!'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Symbols as parameters?
* Gabriel Genellina: En Fri, 22 Jan 2010 10:16:50 -0300, Alf P. Steinbach al...@start.no escribió: I get the impression that there's some message traffic that I don't see, perhaps on the mailing list, since (a) I haven't seen that about 'locals' pointed out by anyone else in this thread, and I think I've read all messages in the thread, and (b) sometimes threads pop up that start with a reply. For example, the recent thread Covert number into string started with a /reply/ in my newreader, using EternalSeptember's NNTP host. It also starts with a reply in Google's archives, url: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b8097d4de4a9c9b0/cb3a2e6ccd7736ef. gmane (news.gmane.org) is a newsserver that acts as a bridge news - mailing lists. The post that started the thread you mention is available there, as well as those previous posts in this thread about the danger of using locals() Thanks. I have gmane in Thunderbird (after all, IIRC gmane is Norwegian! :-) ), but only with one obscure list. Cheers, - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
Jan Kaliszewski wrote: But the corret results even more distinctly support my thesis -- that for n=None using n=sys.maxint (consume3) is noticeably faster than 0-maxlen deque (consume1 and consume2): That advantage may not survive the next release: http://svn.python.org/view/python/trunk/Modules/_collectionsmodule.c?r1=68145r2=70296pathrev=70296 Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: [Edu-sig] some turtle questions
I'm almost sure that there's no way for a turtle to know anything about the background. That's an unfortunate limitation! As for putting a limit on a turtle's travel, you need to write an appropriate conditional. For example, if you want your turtle to stay within a 200x200 square centered around the origin and stop if it gets out, do something roughly like: while(math.abs(t.xcor()) 100 and math.abs(t.ycor()) 100): move turtle Of course, you could instead use if statements and simulate bouncing (if my turtle's x coordinate is beyond my bounding box, subtract from its x coordinate). Best, Hélène. Computer Science Teacher Garfield High School http://garfieldcs.com On Sun, Jan 24, 2010 at 7:29 AM, Brian Blais bbl...@bryant.edu wrote: Hello, I am trying to think of things to do with the turtle module with my students, and I have some ideas where I am not sure whether the turtle module can do it. 1) is there a way to determine the current screen pixel color? I am thinking about having the turtle go forward until it reaches an object, say a red circle. I can probably do this by making circle objects (drawn with turtles themselves) which know their own position, and check against this info. But I thought it might be useful also for the turtle to know. 2) is there a way to put a limit on the extent the turtle can travel? it seems I can keep moving off of the screen. Is there a way to make it so that a forward(50) command, at the edge, either raises an exception (at the wall) or simply doesn't move the turtle because of the limit? thanks! bb -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ ___ Edu-sig mailing list edu-...@python.org http://mail.python.org/mailman/listinfo/edu-sig -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting text at whitespace but keeping the whitespace in the returned list
MRAB, MRAB pyt...@mrabarnett.plus.com wrote: import re re.split(r'(\s+)', Hello world!) ['Hello', ' ', 'world!'] That was exactly (EXACTLY!) the solution I was looking for. Thank you! Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
24-01-2010, 18:24:49 Peter Otten __pete...@web.de wrote: n=None using n=sys.maxint (consume3) is noticeably faster than 0-maxlen deque (consume1 and consume2): That advantage may not survive the next release: http://svn.python.org/view/python/trunk/Modules/_collectionsmodule.c?r1=68145r2=70296pathrev=70296 Nice. :) *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Symbols as parameters?
On Jan 22, 8:39 pm, Martin Drautzburg martin.drautzb...@web.de wrote: Martin Drautzburg wrote: with scope(): # ... # use up, down, left, right here # up, down, left, right no longer defined after the with block exits. Just looked it up again. It's a cool thing. Too bad my locals() hack would still be required. The result would be less noisy (and actually really beautiful) than the decorator implementation though. Thanks again for pointing this out to me. Both in your example and by using a context manager, you can get away with not passing locals() explicitly by introspecting the stack frame. Here's a context manager that does the trick: from __future__ import with_statement from contextlib import contextmanager import sys @contextmanager def enums(*consts): # 2 levels up the stack to bypass the contextmanager frame f_locals = sys._getframe(2).f_locals new_names = set() reset_locals, updated_locals = {}, {} for const in consts: updated_locals[const] = const if const in f_locals: reset_locals[const] = f_locals[const] else: new_names.add(const) f_locals.update(updated_locals) try: yield finally: for name in new_names: del f_locals[name] f_locals.update(reset_locals) if __name__ == '__main__': def move(aDirection): print moving + aDirection up = outerScopeUp with enums(up, down, left, right): move(up) move(down) move(left) move(right) print in the outer scope up is still:, up print this should fail: down Of course, as all other attempts to mess with locals() shown in this thread, this only works when locals() is globals(). If you try it within a function, it fails: def test(): up = outerScopeUp with enums(up, down, left, right): move(up) move(down) move(left) move(right) print in the outer scope up is still:, up print this should fail: down ## XXX: doesn't work within a function test() So it's utility is pretty limited; a custom DSL is probably better suited to your problem. George -- http://mail.python.org/mailman/listinfo/python-list
Re: simple cgi program
In article 4b531bf9$0$1140$4fafb...@reader1.news.tin.it, superpollo ute...@esempio.net wrote: i would like to submit the following code for review. it is a simple common gateway interface program, which uses the least possible libraries for the sake of mechanism undertanding. You should probably factor this into two or three functions. I would not rename urllib here -- it's too common to want to use url for an actual URL. You should not use readline() -- just use read(). Which then obviates the need for the test (there's no real need for using CONTENT_LENGTH for this purpose IIRC). The value for me is wrong unless your cgi is installed as a top-level script. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ import antigravity -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe deal with python command line inside a program
Hi Jonathan, Here is the traceback I got, 'test.py' is where main starts, and I replaced 'sys.executable' with string 'python': args: ['python', 'C:\\myscript.py'] Traceback (most recent call last): File test.py, line 22, in module File subprocess.pyc, line 594, in __init__ File subprocess.pyc, line 816, in _execute_child WindowsError: [Error 2] The system cannot find the file specified On Jan 24, 6:28 am, Jonathan Hartley tart...@tartley.com wrote: On Jan 22, 7:35 pm, susan_kij...@yahoo.ca wrote: Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Python25\\python.exe'', how can I make this work in executable package through py2exe? I have to fix the following problems: -Source code shouldn't exposed in an executable program -Since python environment is not required when running an executable program, how to deal with the situation that C:\\Python25\ \python.exe is required as part of command? Thanks in advance! Hi. What does it do when you try to execute it with py2exe? Does it fail to run? What is the error?- Hide quoted text - - Show quoted text - -- http://mail.python.org/mailman/listinfo/python-list
Re: Default path for files
Rotwang sg...@hotmail.co.uk wrote: Check out http://docs.python.org/library/os.html and the function chdir it is what you are looking for. Thank you. So would adding import os os.chdir(path) to site.py (or any other module which is automatically imported during initialisation) change the default location to path every time I used Python? Don't change the library modules. It would catch you anytime when you expect it least. See for the environment variable PYTHONSTARTUP and the associated startup file. Best regards, Günther -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe deal with python command line inside a program
On Jan 24, 6:35 am, Chris Rebert c...@rebertia.com wrote: On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley tart...@tartley.com wrote: On Jan 22, 7:35 pm, susan_kij...@yahoo.ca wrote: Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Python25\\python.exe'', how can I make this work in executable package through py2exe? I have to fix the following problems: -Source code shouldn't exposed in an executable program -Since python environment is not required when running an executable program, how to deal with the situation that C:\\Python25\ \python.exe is required as part of command? Thanks in advance! Hi. What does it do when you try to execute it with py2exe? Does it fail to run? What is the error? Thanks for pointing that, this time I try to use 'python' as the arg, I got an error: WindowsError: [Error 2] The system cannot find the file specified Because the subprocess is looking for a source code location, and which was hard coded, any suggestion to work out the issue? The subprocess call would fail utterly since sys.executable is apparently inaccurate for py2exe-generated executables. Cheers, Chris --http://blog.rebertia.com- Hide quoted text - - Show quoted text - -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe deal with python command line inside a program
On Sun, Jan 24, 2010 at 10:25 AM, im_smialing susan_kij...@yahoo.ca wrote: On Jan 24, 6:35 am, Chris Rebert c...@rebertia.com wrote: On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley tart...@tartley.com wrote: On Jan 22, 7:35 pm, susan_kij...@yahoo.ca wrote: Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Python25\\python.exe'', how can I make this work in executable package through py2exe? I have to fix the following problems: -Source code shouldn't exposed in an executable program -Since python environment is not required when running an executable program, how to deal with the situation that C:\\Python25\ \python.exe is required as part of command? Thanks in advance! Hi. What does it do when you try to execute it with py2exe? Does it fail to run? What is the error? Thanks for pointing that, this time I try to use 'python' as the arg, I got an error: WindowsError: [Error 2] The system cannot find the file specified Because the subprocess is looking for a source code location, and which was hard coded, any suggestion to work out the issue? Famous last words, but I think it's impossible. You'd have to somehow specify the Python interpreter inside the py2exe-generated executable as the program for subprocess.Popen to run, but I sincerely doubt that can be done. I would suggest something involving os.fork(), but you're clearly on Windows, which doesn't support fork(), so that option's out. The closest thing that leaves is execfile(): http://docs.python.org/library/functions.html#execfile Or you could relax your constraints: You could require Python to be installed on the system (I think there are ways to have your program's installer run the Python installer without any user interaction), or you could give up trying to keep the source code secret (it's illegal for your users to redistribute or modify it anyway, assuming you use the right EULA, and py2exe doesn't keep your sourcecode secret anyway - http://stackoverflow.com/questions/261638/how-do-i-protect-python-code) Cheers, Chris -- http://blog.rebertia.com The subprocess call would fail utterly since sys.executable is apparently inaccurate for py2exe-generated executables. -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Jan 24, 3:20 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 24 Jan 2010 02:33:36 -0800, Steve Howell wrote: You are also a brilliant computer scientist, despite the fact that you are defending a list implemenation that can't pop the first element off the list in O(1) time. You say that like it's a bad thing. It is. It's very simple: the trade-offs that the Python development team have deliberately chosen aren't the same trade-offs that you prefer. That doesn't make your trade-offs right and Python's wrong. They're just different, and if Python lists had your preferred implementation, I guarantee that somebody would be complaining about it right now. If you're serious about wanting O(1) pops from the start of the list, write your own list implementation and use it. You might even like to make it public, so others can use it as well. But please stop with the snide remarks and poorly disguised insults and back-handed compliments, it's getting tedious. I will stop being snide, but I will be blunt, and if anybody interprets my criticism as an insult, so be it. The current algorithm is broken. It's a 20th century implementation of lists built on top of a 20th century memory manager. It's at least ten years behind the times. Or just change your algorithm slightly -- it's not hard to turn an algorithm that pops from the start of a list to one that pops from the end of the list. The fact that you are proposing to reverse a list to work around its performance deficiencies just confirms to me that the algorithm is broken. I will concede the fact that most of CPython's tradeoffs are driven by the limitations of the underlying memory manager. If realloc () allowed you to easily release memory from the front of a previously allocated block, we'd be talking about maybe a 10-line patch here, and it wouldn't impact even list_resize() in a meaningful way. Even with realloc()'s brokenness, you could improve pop(0) in a way that does not impact list access at all, and the patch would not change the time complexity of any operation; it would just add negligible extract bookkeeping within list_resize() and a few other places. The objection that the extra pointer would increase the size of list objects is totally 20th century thinking. It would be totally negligible for any real world program. -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Jan 23, 3:04 pm, Terry Reedy tjre...@udel.edu wrote: On 1/23/2010 12:17 PM, Steve Howell wrote: Terry Reedy said: ''' If you try writing a full patch, as I believe someone did, or at least a prototype thereof, when the idea was discussed, you might have a better idea of what the tradeoffs are and why it was rejected. ''' I have to run, but tomorrow I will try to dig through python-dev archives and find the patch. If anybody has hints on where to look for it (anybody remember the author, for example?), it would be much appreciated. The approach you outlined in your other response to me is, I believe, what was considered, investigated, and then rejected (by Guido, with agreement). The discussion may have been on the now-closed and (misspelled) pyk3 (?), or maybe on python-ideas, but my memory is more likely the former. I am sure that Raymond H. was involved also. If the patch looks simple, I will try to pitch the idea that its time has come. Now that the specification of the language itself is frozen, I think there might be more room for improving implementations. Also, I might be able to make the argument that tradeoffs of memory vs. CPU vs. code complexity have different forces in the 2010s. I am not opposed to a possible change, just hasty, ill-informed criticism. If there is not a PEP on this issue, it would be good to have one that recorded the proposal and the pros and cons, regardless of the outcome, so there would be something to refer people to. If that had been already done, it would have shortened this thread considerably. I think it's a good idea to write a PEP on this issue, and I will attempt a first draft. I think I should submit the first draft to python-ideas, correct? I expect the PEP to be at least initially, if not permanently, rejected, but it would not be an exercise in futility, as I agree it's good to record pros and cons of the proposal in one place. The PEP probably would not include a proposed patch until there was a little bit of consensus behind it, but it would not take me a lot of time to present the basic argument. Here is my sketch of what the PEP would look like. Proposal: Improve list's implementation so that deleting elements from the front of the list does not require an O(N) memmove operation. Rationale: Some Python programs that process lists have multiple methods that consume the first element of the list and pop it off. The pattern comes up with parsers in particular, but there are other examples. It is possible now, of course, to use a data structure in Python that has O(1) for deleting off the top of the list, but none of the alternatives fully replicate the benefits of list itself. Specification: Improving CPython's performance does not affect the language itself, so there are no bikeshed arguments to be had with respect to syntax, etc. Any patch would, of course, affect the performance of nearly every Python program in existence, so any patch would have to, at a bare minimum: 1) Not increase the time or memory complexity of any other list operation. 2) Not affect list access at all. 3) Minimally affect list operations that mutate the list. 4) Be reasonably simple within CPython itself. 5) Not be grossly wasteful of memory. Backwards Compatibility: See above. An implementation of this PEP would not change the definition of the language in any way, but it would have to minimally impact the performance of lists for the normal use cases. Implementation: There are two ways to make deleting the first item of the list run more efficiently. The most ambitious proposal is to fix the memory manager itself to allow the release of memory from the start of the chunk. The advantage of this proposal is that it would simplify the changes to list itself, and possibly have collateral benefits for other CPython internal data structures. The disadvantage of the proposal is that there is a strong tradition in CPython to use native memory management, particularly with respect to the fact that it runs on many platforms. The less ambitious proposal is to change the memory management scheme within list itself. There is already precedent in list_resize() to optimistically allocate memory, so it is not a great break from tradition to optimistically defer the release of memory. But it would complicate things. References: I would refer to this thread on comp.lang.python for discussion, and I would also try to dig up older threads on python-dev or elsewhere. -- http://mail.python.org/mailman/listinfo/python-list
Terminal application with non-standard print
Hello everyone, I would like to do a Python application that prints data to stdout, but not the common way. I do not want the lines to be printed after each other, but the old lines to be replaced with the new ones, like wget does it for example (when downloading a file you can see the percentage increasing on a same line). I looked into the curses module, but this seems adapted only to do a whole application, and the terminal history is not visible anymore when the application starts. Any ideas? Thanks, Remi -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
In article b4440231-f33f-49e1-9d6f-5fbce0a63...@b2g2000yqi.googlegroups.com, Steve Howell showel...@yahoo.com wrote: Even with realloc()'s brokenness, you could improve pop(0) in a way that does not impact list access at all, and the patch would not change the time complexity of any operation; it would just add negligible extract bookkeeping within list_resize() and a few other places. Again, your responsibility is to provide a patch and a spectrum of benchmarking tests to prove it. Then you would still have to deal with the objection that extensions use the list internals -- that might be an okay sell given the effort otherwise required to port extensions to Python 3, but that's not the way to bet. Have you actually read the discussions you were pointed at? -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ import antigravity -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminal application with non-standard print
On 2010-01-24, R?mi babedo...@yahoo.fr wrote: I would like to do a Python application that prints data to stdout, but not the common way. I do not want the lines to be printed after each other, but the old lines to be replaced with the new ones, like wget does it for example (when downloading a file you can see the percentage increasing on a same line). sys.stdout.write(Here's the first line) time.sleep(1) sys.stdout.write(\rAnd this line replaces it.) -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminal application with non-standard print
Thank you for your answer, but that does not work : the second line is printed after the first one. -- Rémi Grant Edwards wrote: On 2010-01-24, R?mi babedo...@yahoo.fr wrote: I would like to do a Python application that prints data to stdout, but not the common way. I do not want the lines to be printed after each other, but the old lines to be replaced with the new ones, like wget does it for example (when downloading a file you can see the percentage increasing on a same line). sys.stdout.write(Here's the first line) time.sleep(1) sys.stdout.write(\rAnd this line replaces it.) -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Python 2.5.5 Release Candidate 2.
On behalf of the Python development team and the Python community, I'm happy to announce the release candidate 2 of Python 2.5.5. This is a source-only release that only includes security fixes. The last full bug-fix release of Python 2.5 was Python 2.5.4. Users are encouraged to upgrade to the latest release of Python 2.6 (which is 2.6.4 at this point). This releases fixes issues with the logging and tarfile modules, and with thread-local variables. Since the release candidate 1, additional bugs have been fixed in the expat module. See the detailed release notes at the website (also available as Misc/NEWS in the source distribution) for details of bugs fixed. For more information on Python 2.5.5, including download links for various platforms, release notes, and known issues, please see: http://www.python.org/2.5.5 Highlights of the previous major Python releases are available from the Python 2.5 page, at http://www.python.org/2.5/highlights.html Enjoy this release, Martin Martin v. Loewis mar...@v.loewis.de Python Release Manager (on behalf of the entire python-dev team) -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Jan 24, 11:28 am, a...@pythoncraft.com (Aahz) wrote: In article b4440231-f33f-49e1-9d6f-5fbce0a63...@b2g2000yqi.googlegroups.com, Steve Howell showel...@yahoo.com wrote: Even with realloc()'s brokenness, you could improve pop(0) in a way that does not impact list access at all, and the patch would not change the time complexity of any operation; it would just add negligible extract bookkeeping within list_resize() and a few other places. Again, your responsibility is to provide a patch and a spectrum of benchmarking tests to prove it. Then you would still have to deal with the objection that extensions use the list internals -- that might be an okay sell given the effort otherwise required to port extensions to Python 3, but that's not the way to bet. Ok. Have you actually read the discussions you were pointed at? I don't think anybody provided an actual link, but please correct me if I overlooked it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminal application with non-standard print
On 2010-01-24, R?mi babedo...@yahoo.fr wrote: Thank you for your answer, but that does not work: Works fine for me. the second line is printed after the first one. Not when I run it. There's not much more I can say given the level of detail you've provided. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
def consume2(iterator, n): # the approved proposal (see #7764) if n is None: collections.deque(iterator, maxlen=0) else: next(islice(iterator, n, n), None) FWIW, the deque() approach becomes even faster in Py2.7 and Py3.1 which has a high-speed path for the case where maxlen is zero. Here's a snippet from Modules/_collectionsmodule.c: /* Run an iterator to exhaustion. Shortcut for the extend/extendleft methods when maxlen == 0. */ static PyObject* consume_iterator(PyObject *it) { PyObject *item; while ((item = PyIter_Next(it)) != NULL) { Py_DECREF(item); } Py_DECREF(it); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; } This code consumes an iterator to exhaustion. It is short, sweet, and hard to beat. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On 1/24/2010 2:26 PM, Steve Howell wrote: I think it's a good idea to write a PEP on this issue, and I will attempt a first draft. I think I should submit the first draft to python-ideas, correct? That is not a *requirement* for drafts in general, but it is a good idea for a community or community-person generated proposal, such as this one. I expect the PEP to be at least initially, if not permanently, rejected, Guido sometimes rejects 'no-chance' proposals without waiting to be asked, but he usually waits until the PEP author feels the issue is ripe and asks for a pronouncement. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Symbols as parameters?
Just top-posting for clarity. :-) code file=directions.py up = UP left= LEFT down= DOWN right = RIGHT /code code file=locals.py # This code is not guaranteed to work by the language specification. # But it is one way to do the solution I presented earlier in the thread. import sys def import_from( module_name ): local_variables = sys._getframe( 1 ).f_locals m = __import__( module_name, globals(), local_variables, * ) for name in local_variables: if not name.startswith( _ ): local_variables[name] = getattr( m, name ) def move( direction ): print( Moving + str( direction ) ) def test(): up = outerScopeUp class using_directions: (up, left, down, right) = 4*[None]; import_from( directions ) move( up ) move( down ) move( left ) move( right ) print( in the outer scope up is still: + up ) print( this should fail: ) down test() /code output pyversions=2.x and 3.x Moving UP Moving DOWN Moving LEFT Moving RIGHT in the outer scope up is still: outerScopeUp this should fail: Traceback (most recent call last): File locals.py, line 29, in module test() File locals.py, line 27, in test down NameError: global name 'down' is not defined /output Cheers hth., - Alf * George Sakkis: On Jan 22, 8:39 pm, Martin Drautzburg martin.drautzb...@web.de wrote: Martin Drautzburg wrote: with scope(): # ... # use up, down, left, right here # up, down, left, right no longer defined after the with block exits. Just looked it up again. It's a cool thing. Too bad my locals() hack would still be required. The result would be less noisy (and actually really beautiful) than the decorator implementation though. Thanks again for pointing this out to me. Both in your example and by using a context manager, you can get away with not passing locals() explicitly by introspecting the stack frame. Here's a context manager that does the trick: from __future__ import with_statement from contextlib import contextmanager import sys @contextmanager def enums(*consts): # 2 levels up the stack to bypass the contextmanager frame f_locals = sys._getframe(2).f_locals new_names = set() reset_locals, updated_locals = {}, {} for const in consts: updated_locals[const] = const if const in f_locals: reset_locals[const] = f_locals[const] else: new_names.add(const) f_locals.update(updated_locals) try: yield finally: for name in new_names: del f_locals[name] f_locals.update(reset_locals) if __name__ == '__main__': def move(aDirection): print moving + aDirection up = outerScopeUp with enums(up, down, left, right): move(up) move(down) move(left) move(right) print in the outer scope up is still:, up print this should fail: down Of course, as all other attempts to mess with locals() shown in this thread, this only works when locals() is globals(). If you try it within a function, it fails: def test(): up = outerScopeUp with enums(up, down, left, right): move(up) move(down) move(left) move(right) print in the outer scope up is still:, up print this should fail: down ## XXX: doesn't work within a function test() So it's utility is pretty limited; a custom DSL is probably better suited to your problem. -- http://mail.python.org/mailman/listinfo/python-list
easy_install error ...
All, I am running into issue with easy install error, see error below: python setup.py easy_install -m 'docutils==0.4' running easy_install error: Not a URL, existing file, or requirement spec: 'docutils==0.4' any idea as to why? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminal application with non-standard print
My apologies, I did not run the lines properly. Thanks, that works great now. If I understand well, \r erases the last line. How about erasing the previous lines? For example when writing sys.stdout.write(1\n2\n) sys.stdout.write(\r3) the 1 is still visible. -- Rémi On 24 jan, 20:53, Grant Edwards inva...@invalid.invalid wrote: On 2010-01-24, R?mi babedo...@yahoo.fr wrote: Thank you for your answer, but that does not work: Works fine for me. the second line is printed after the first one. Not when I run it. There's not much more I can say given the level of detail you've provided. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: [Edu-sig] some turtle questions
* Helene Martin: I'm almost sure that there's no way for a turtle to know anything about the background. That's an unfortunate limitation! The background for the turtle is just a Tkinter canvas. So yes, it's technically possible to inspect things there, since there is method to obtain the canvas. But unfortunately the canvas is not a bitmapped picture: it just maintains a list of objects to draw (vector graphics, metafile graphics). And so there's no practical way to obtain the current screen pixel color as Brian asks for: there are no pixels in that canvas... Blatant plug: I included some perhaps interesting turtle examples in ch 2 of my writings at url: http://tinyurl.com/programmingbookP3. It starts with some silly figures, then graph drawing, then some recursive figures (idealized tree, C-curve, dragoncurve). Helene: since I'm not on the original list, could you perhaps forward to that list or to the original poster? Thanks, - Alf As for putting a limit on a turtle's travel, you need to write an appropriate conditional. For example, if you want your turtle to stay within a 200x200 square centered around the origin and stop if it gets out, do something roughly like: while(math.abs(t.xcor()) 100 and math.abs(t.ycor()) 100): move turtle Of course, you could instead use if statements and simulate bouncing (if my turtle's x coordinate is beyond my bounding box, subtract from its x coordinate). Best, Hélène. Computer Science Teacher Garfield High School http://garfieldcs.com On Sun, Jan 24, 2010 at 7:29 AM, Brian Blais bbl...@bryant.edu wrote: Hello, I am trying to think of things to do with the turtle module with my students, and I have some ideas where I am not sure whether the turtle module can do it. 1) is there a way to determine the current screen pixel color? I am thinking about having the turtle go forward until it reaches an object, say a red circle. I can probably do this by making circle objects (drawn with turtles themselves) which know their own position, and check against this info. But I thought it might be useful also for the turtle to know. 2) is there a way to put a limit on the extent the turtle can travel? it seems I can keep moving off of the screen. Is there a way to make it so that a forward(50) command, at the edge, either raises an exception (at the wall) or simply doesn't move the turtle because of the limit? thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
Steve Howell showel...@yahoo.com writes: Proposal: Improve list's implementation so that deleting elements from the front of the list does not require an O(N) memmove operation. ... It is possible now, of course, to use a data structure in Python that has O(1) for deleting off the top of the list, but none of the alternatives fully replicate the benefits of list itself. I think you are mostly referring to deque. Why don't you instead say what you think is wrong with using deque, and how deque can be improved? See above. An implementation of this PEP would not change the definition of the language in any way, but it would have to minimally impact the performance of lists for the normal use cases. But you're talking about adding one or two words to EVERY list, and many normal use cases allocate a LOT of lists. Those use cases are likely more common than use cases that pop from the front of the list but for some reason can't use deque. The most ambitious proposal is to fix the memory manager itself to allow the release of memory from the start of the chunk. That's inappropriate given the memory fragmentation it would cause. Really, you're describing a problem that arises in a few programs but up til now, as far as I know, everyone has found deque to be an adequate solution. Your approach of snarling against list is not persuading anyone that list needs to be changed, because most everyone is satisfied with the existing solution. You might change approaches and discuss deque, what's wrong with it, and whether it can be fixed. Getting a change approved for deque is probably much easier than getting one approved for list, just because nowhere near as many things depend on deque's performance. And when discussing performance in this context, additive constants do matter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
Raymond Hettinger pyt...@rcn.com writes: This code consumes an iterator to exhaustion. It is short, sweet, and hard to beat. I've always used sum(1 for x in iterator) or some such. -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO module for binomial coefficients, etc.
Alf P. Steinbach wrote: div class=moz-text-flowed style=font-family: -moz-fixed* Dave Angel: kj wrote: Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorials (on the order of 1!), using floating-point approximations as needed, and is smart about optimizations, memoizations, etc. TIA! ~K You do realize that a standard. python floating point number cannot possibly approximate a number like 1! I think what kj is looking for, provided she/he is knowledgable about the subject, is code that does something like from math import * log_fac = 0 for i in range( 1, 1+1 ): ... log_fac += log( i, 10 ) ... print( 1! = {}e{}.format( 10**(log_fac % 1), int( log_fac ) ) ) 1! = 2.84625968062e35659 _ which turned out to be accurate to 10 digits. Better use longs. That would involve incredible overhead. E.g., how many bytes for the number above? Those bytes translate into arithmetic overhead. About 14k. I'd check out the gamma function, which matches factorial for integer arguments (plus or minus 1). Or, e.g., logarithms... ;-) Cheers hth., - Alf I didn't think of simply summing the logs. I did have some optimizations in mind for the multiply of the longs. If you do lots of partial products, you can do a good bit of the work with smaller numbers, and only get to longs when those partial products get big enough. You could also use scaling when the numbers do start getting bigger. But I still think there must be code for the gamma function that would be quicker. But I haven't chased that lead. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe deal with python command line inside a program
Thanks for taking time to help me. If I use either way, requiring python being installed, or allow source codes exposure, it seems in some degree, there's not necessarily to make the executable package any more, which is very frustrating Suppose I take the first way, python environment must be on a machine, how can I have py2exe find a specific file path, for instance as below, 2 up levels from running director, how to find myscript.py in py2exe? Since in customers' machines, C:\dev\mysricpt.py doesn't exist python environment: running directory - C:\dev\level1\level2\test.py, suprocess directory-C:\dev\mysricpt.py py2exe C:\dev\level1\level2\dist On Jan 24, 1:50 pm, Chris Rebert c...@rebertia.com wrote: On Sun, Jan 24, 2010 at 10:25 AM, im_smialing susan_kij...@yahoo.ca wrote: On Jan 24, 6:35 am, Chris Rebert c...@rebertia.com wrote: On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley tart...@tartley.com wrote: On Jan 22, 7:35 pm, susan_kij...@yahoo.ca wrote: Hi, I need to create a python subprogress, like this: myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE) sys.executable was printed out as ''C:\\Python25\\python.exe'', how can I make this work in executable package through py2exe? I have to fix the following problems: -Source code shouldn't exposed in an executable program -Since python environment is not required when running an executable program, how to deal with the situation that C:\\Python25\ \python.exe is required as part of command? Thanks in advance! Hi. What does it do when you try to execute it with py2exe? Does it fail to run? What is the error? Thanks for pointing that, this time I try to use 'python' as the arg, I got an error: WindowsError: [Error 2] The system cannot find the file specified Because the subprocess is looking for a source code location, and which was hard coded, any suggestion to work out the issue? Famous last words, but I think it's impossible. You'd have to somehow specify the Python interpreter inside the py2exe-generated executable as the program for subprocess.Popen to run, but I sincerely doubt that can be done. I would suggest something involving os.fork(), but you're clearly on Windows, which doesn't support fork(), so that option's out. The closest thing that leaves is execfile():http://docs.python.org/library/functions.html#execfile Or you could relax your constraints: You could require Python to be installed on the system (I think there are ways to have your program's installer run the Python installer without any user interaction), or you could give up trying to keep the source code secret (it's illegal for your users to redistribute or modify it anyway, assuming you use the right EULA, and py2exe doesn't keep your sourcecode secret anyway -http://stackoverflow.com/questions/261638/how-do-i-protect-python-code) Cheers, Chris --http://blog.rebertia.com The subprocess call would fail utterly since sys.executable is apparently inaccurate for py2exe-generated executables. -- http://mail.python.org/mailman/listinfo/python-list
start .pyo files with doubleclick on windows
Hi, I'd like to start .pyo files under windows with a double click. (I know I can just write a .bat wrapper, but somehow it would be more fun to start with a direct double click) Currently this works if the file does not import any other .pyo file. The problem is, that a dobleclick performs a python.exe myfile.pyo In order to import precompiled .pyo files however it seems, that python.exe -OO myfile.pyo would be required. Is there any trick to do this under windows? The only trick, that I can think of is to write a small wrapper executable, that would then call python -OO. Wouldn't it be useful if python searched also for .pyo files when trying to import and being invoked with python.exe mycode.pyo thanks in advance for any ideas suggestion -- http://mail.python.org/mailman/listinfo/python-list
Re: start .pyo files with doubleclick on windows
* News123: Hi, I'd like to start .pyo files under windows with a double click. (I know I can just write a .bat wrapper, but somehow it would be more fun to start with a direct double click) Currently this works if the file does not import any other .pyo file. The problem is, that a dobleclick performs a python.exe myfile.pyo In order to import precompiled .pyo files however it seems, that python.exe -OO myfile.pyo would be required. Is there any trick to do this under windows? The only trick, that I can think of is to write a small wrapper executable, that would then call python -OO. Wouldn't it be useful if python searched also for .pyo files when trying to import and being invoked with python.exe mycode.pyo thanks in advance for any ideas suggestion C:\ assoc .pyo .pyo=Python.CompiledFile C:\ ftype python.compiledfile python.compiledfile=C:\Program Files\cpython\python31\python.exe %1 %* C:\ _ Use ftype to change the association. Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.5.1.1/dictionary] Change sorting order?
On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. display the list from A...Zdigits the first time, then B...ZAdigits, etc. Thanks everyone for the great feedback. I ended up using - a list instead of a dictionary to hold the list of names - use the random library to pick a character from which to start listing names (simpler than saving the next letter into a file, and starting from this the next time the loop is gone through) For those interested, here's some working code: == import random connected = [_test,-test,0test,1test,Aa,Aab,Bb,B,Cc,Ccaa] connected.sort() #Fill list with non-duplicate first letter of all items characters=[] for name in connected: char = name[0] #if this character not in list, add to array if not char in characters: characters.append(char) #Pick a random character from which to start iterating index = random.randint(0,len(characters)-1) startch = characters[index] print Will start from %s % startch #Go through list starting with items that start with 'starch', and rotate from beginning result = [name for name in connected if name[0] = startch] + [name for name in connected if name[0] startch] print result == Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO module for binomial coefficients, etc.
On Jan 23, 2:55 pm, kj no.em...@please.post wrote: Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorials (on the order of 1!), using floating-point approximations as needed, and is smart about optimizations, memoizations, etc. TIA! ~K If you need exact values, gmpy (http://code.google.com/p/gmpy/) has basic, but fast, support for calculating binomial coefficients and factorials. If you are floating point approximations, check out mpmath (http://code.google.com/p/mpmath/). casevh -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Sun, Jan 24, 2010 at 1:53 PM, Steve Howell showel...@yahoo.com wrote: I don't think anybody provided an actual link, but please correct me if I overlooked it. I have to wonder if my messages are all ending up in your spam folder for some reason. :-) PEP 3128 (which solves your problem, but not using the implementation you suggest) http://www.python.org/dev/peps/pep-3128/ Implementation as an extension module: http://pypi.python.org/pypi/blist/ Related discussion: http://mail.python.org/pipermail/python-3000/2007-April/006757.html http://mail.python.org/pipermail/python-3000/2007-May/007491.html Detailed performance comparison: http://stutzbachenterprises.com/performance-blist I maintain a private fork of Python 3 with the blist replacing the regular list, as a way of rigorously testing the blist implementation. Although I originally proposed a PEP, I am content to have the blist exist as a third-party module. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -- http://mail.python.org/mailman/listinfo/python-list
Re: start .pyo files with doubleclick on windows
Hi Alf, Alf P. Steinbach wrote: * News123: Hi, I'd like to start .pyo files under windows with a double click. C:\ assoc .pyo .pyo=Python.CompiledFile C:\ ftype python.compiledfile python.compiledfile=C:\Program Files\cpython\python31\python.exe %1 %* C:\ _ Use ftype to change the association. Thanks a lot, I leared something new about Windows What I did now is this: assoc .pyo=Python.CompiledOptimizedFile ftype Python.CompiledOptimizedFile=C:\Python26\python.exe -OO %1 %* bye N Cheers hth., - Alf -- http://mail.python.org/mailman/listinfo/python-list
Broken Python 2.6 installation on Ubuntu Linux 8.04
Hello everyone, I've posted this same question over on ubuntuforums.org, so I'm trying to get help in all of the logical places. I'm running Ubuntu Linux 8.04 (Hardy) on a fairly new x86 box, with two hard disks in a software RAID 1 configuration. Hardy comes with Python 2.5 as a standard package, but not 2.6. I would really like to have the combinations function that is included with itertools in Python 2.6. I tried writing a combinations function of my own, but it's SLOW and uses a HUGE amount of memory. So, in my case the Linux Synaptic Package Manager cannot be used to install Python 2.6. I therefore attempted a manual installation. I downloaded the Linux tarball for Python 2.6 from python.org. I followed the installation instructions, and they appeared to execute fine. But when I started IDLE, I still had Python 2.5. No good. I do most of my editing in SCIte. Apparently SCIte knows that I have Python 2.6, and is trying to use it. Alas, my programs depend on extra Python packages such as biopython, numpy and matplotlib. My Python 2.6 distro does not have these yet. None of my programs will run from SCIte! Looking down into the details of the install, I've discovered that Hardy placed the Python 2.4 and 2.5 executables in /usr/bin. My Python 2.6 installation ended up in /usr/local/bin. This may be contributing to my problems. Given the mess I've made by trying to just install plain-old Python, I don't know whether I should attempt to back out, or to press on. Can I convince IDLE to connect to Python 2.6? How do I manually install site packages? Alternately, I COULD upgrade my Ubuntu Linux to 9.4 (Jaunty) or 9.10 (Karmic). Python 2.6 comes standard with both of these. But this is why I mentioned that my storage is RAID1. Apparently, upgrading with RAID present is a serious headache. The Linux wizards are supposed to be fixing these problems in the next release, due in April. I could wait, I suppose. In the mean time, I may have to uninstall Python 2.6 and get my 2.5 running again. I have not found any instructions for how to do that. Help! -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.5.1.1/dictionary] Change sorting order?
Gilles Ganault nos...@nospam.com writes: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. display the list from A...Zdigits the first time, then B...ZAdigits, etc. Thanks everyone for the great feedback. I ended up using - a list instead of a dictionary to hold the list of names - use the random library to pick a character from which to start listing names (simpler than saving the next letter into a file, and starting from this the next time the loop is gone through) For those interested, here's some working code: == import random connected = [_test,-test,0test,1test,Aa,Aab,Bb,B,Cc,Ccaa] connected.sort() #Fill list with non-duplicate first letter of all items characters=[] for name in connected: char = name[0] #if this character not in list, add to array if not char in characters: characters.append(char) characters = list(set(name[0] for name in connected)) #Pick a random character from which to start iterating index = random.randint(0,len(characters)-1) startch = characters[index] startch = random.choice(characters) print Will start from %s % startch #Go through list starting with items that start with 'starch', and rotate from beginning result = [name for name in connected if name[0] = startch] + [name for name in connected if name[0] startch] It would make sense to keep track of the indices where the first word starting with a certain letter starts in the earlier part of the code and to use it now to 'rotate' the list. print result == Thanks again. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Broken Python 2.6 installation on Ubuntu Linux 8.04
On Sun, Jan 24, 2010 at 5:53 PM, John Ladasky lada...@my-deja.com wrote: Hello everyone, I've posted this same question over on ubuntuforums.org, so I'm trying to get help in all of the logical places. I'm running Ubuntu Linux 8.04 (Hardy) on a fairly new x86 box, with two hard disks in a software RAID 1 configuration. Hardy comes with Python 2.5 as a standard package, but not 2.6. I would really like to have the combinations function that is included with itertools in Python 2.6. I tried writing a combinations function of my own, but it's SLOW and uses a HUGE amount of memory. So, in my case the Linux Synaptic Package Manager cannot be used to install Python 2.6. I therefore attempted a manual installation. I downloaded the Linux tarball for Python 2.6 from python.org. I followed the installation instructions, and they appeared to execute fine. But when I started IDLE, I still had Python 2.5. No good. How did you start IDLE? If you started it by going to the Applications menu, it still points to the Python 2.5 idle. If you open up a terminal and run idle, it should run Python 2.6. If it doesn't, make a .bashrc file in your home directory and add the line $PATH=/usr/local/bin:$PATH. I do most of my editing in SCIte. Apparently SCIte knows that I have Python 2.6, and is trying to use it. Alas, my programs depend on extra Python packages such as biopython, numpy and matplotlib. My Python 2.6 distro does not have these yet. None of my programs will run from SCIte! Extensions written in C must be recompiled for every version of Python. Since you're using a version of Python not available through the package manager, your packages are also not available through that. You'll have to download the sources for those and compile them by hand to. This is why most people stick with the precompiled binaries. Looking down into the details of the install, I've discovered that Hardy placed the Python 2.4 and 2.5 executables in /usr/bin. My Python 2.6 installation ended up in /usr/local/bin. This may be contributing to my problems. It shouldn't be. /usr/local/bin should already be on your path in front of /usr/bin. If it isn't put it there (that's what the .bashrc file I listed before does) Given the mess I've made by trying to just install plain-old Python, I don't know whether I should attempt to back out, or to press on. Can I convince IDLE to connect to Python 2.6? How do I manually install site packages? Download the package sources and compile them yourself. Python packages have a very easy way to do that- just cd into the source folder and run python setup.py install Alternately, I COULD upgrade my Ubuntu Linux to 9.4 (Jaunty) or 9.10 (Karmic). Python 2.6 comes standard with both of these. But this is why I mentioned that my storage is RAID1. Apparently, upgrading with RAID present is a serious headache. The Linux wizards are supposed to be fixing these problems in the next release, due in April. I could wait, I suppose. In the mean time, I may have to uninstall Python 2.6 and get my 2.5 running again. I have not found any instructions for how to do that. Your Python2.5 installation is just fine. You can get to it by running python2.5 at the command line (as opposed to python which should run python2.6) Help! -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Embed PHP in HTML print
NickC wrote: On Sun, 24 Jan 2010 10:37:51 +, Duncan Booth wrote: content with ajax. Alternatively, use urllib in Python to retrieve a page from the Apache server and insert that into its own output: that Thanks for hint on urllib. I shake my head in amazement with python sometimes. I'll write it here: print urllib.urlopen('http://myserver.com/phpscript.php').read() That's it. *One* line. The output from the php script is: a href='zenphoto/kitty/IMG_0759.jpg' title='Random Picture...' img src='zenphoto/cache/kitty/IMG_0759_800.jpg' alt=random image IMG_0759 //a and the one-liner seamlessly prints that to insert it into the html output. And I thought it would be hard; I should have known better. Always great to see Python doing impressive things for new users. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS:http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Consume an iterable
Raymond Hettinger wrote: FWIW, the deque() approach becomes even faster in Py2.7 and Py3.1 which has a high-speed path for the case where maxlen is zero. Here's a snippet from Modules/_collectionsmodule.c: /* Run an iterator to exhaustion. Shortcut for the extend/extendleft methods when maxlen == 0. */ static PyObject* consume_iterator(PyObject *it) { PyObject *item; while ((item = PyIter_Next(it)) != NULL) { Py_DECREF(item); } Py_DECREF(it); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; } This code consumes an iterator to exhaustion. It is short, sweet, and hard to beat. islice() is still a tad faster. A possible optimization: static PyObject* consume_iterator(PyObject *it) { PyObject *item; PyObject *(*iternext)(PyObject *); iternext = *Py_TYPE(it)-tp_iternext; while ((item = iternext(it)) != NULL) { Py_DECREF(item); } Py_DECREF(it); if (PyErr_Occurred()) { if(PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); else return NULL; } Py_RETURN_NONE; } Before: $ ./python -m timeit -sfrom itertools import repeat, islice; from collections import deque; from sys import maxint next(islice(repeat(None, 1000), maxint, maxint), None) 10 loops, best of 3: 6.49 usec per loop $ ./python -m timeit -sfrom itertools import repeat, islice; from collections import deque; from sys import maxint deque(repeat(None, 1000), maxlen=0) 10 loops, best of 3: 9.93 usec per loop After: $ ./python -m timeit -sfrom itertools import repeat, islice; from collections import deque; from sys import maxint deque(repeat(None, 1000), maxlen=0) 10 loops, best of 3: 6.31 usec per loop Peter PS: Two more, for Paul Rubin: $ ./python -m timeit -sfrom itertools import repeat sum(0 for _ in repeat(None, 1000)) 1 loops, best of 3: 125 usec per loop $ ./python -m timeit -sfrom itertools import repeat sum(0 for _ in repeat(None, 1000) if 0) 1 loops, best of 3: 68.3 usec per loop -- http://mail.python.org/mailman/listinfo/python-list
Re: Broken Python 2.6 installation on Ubuntu Linux 8.04
Benjamin Kaplan wrote: Extensions written in C must be recompiled for every version of Python. Since you're using a version of Python not available through the package manager, your packages are also not available through that. You'll have to download the sources for those and compile them by hand to. This is why most people stick with the precompiled binaries. As far as I remember you can use the Debian build system to create binaries for your Python version. You have to add Python 2.6 to /usr/share/python/debian_defaults and recompile the desired packages with apt-get -b python-yourmodule. This should generate one to several deb files. Install them with dpkg -i filename.deb. It's all documented in /usr/share/doc/python/python-policy.txt.gz, read the file with zless. By the way you mustn't install your own Python with make install, use make altinstall! Your /usr/local/bin/python binary masks the original python command in /usr/bin. You should remove all /usr/local/bin/py* binaries that do not end with 2.6. Otherwise you may and will break existing programs on your system. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes for AIX
Waddle, Jim wrote: Is there a policy concerning getting functions like ctypes working on AIX. If you can get it working, post a patch on the bug tracker. -- - Andrew I MacIntyre These thoughts are mine alone... E-mail: andy...@bullseye.apana.org.au (pref) | Snail: PO Box 370 andy...@pcug.org.au (alt) |Belconnen ACT 2616 Web:http://www.andymac.org/ |Australia -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO module for binomial coefficients, etc.
Dave Angel wrote: But I still think there must be code for the gamma function that would be quicker. But I haven't chased that lead. Log of the gamma function is also an algorithm in its own right (e.g. published in _Numerical Recipes_.) Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Symbols as parameters?
On Sun, 24 Jan 2010 10:11:07 -0800, George Sakkis wrote: Both in your example and by using a context manager, you can get away with not passing locals() explicitly by introspecting the stack frame. You say that as if it were less of an ugly hack than the locals() trick. But sys._getframe is a private implementation detail, so you're no better off. So it's utility is pretty limited; a custom DSL is probably better suited to your problem. Personally, I think the OP is worrying too much about namespace pollution. If you're concerned about the enums of one function clashing with the enums of another, that's a strong hint that they don't belong in the same module. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Broken Python 2.6 installation on Ubuntu Linux 8.04
Thanks, Benjamin, I am getting a handle on this. I've written my own Python modules before, and have installed them using distutils. So I know that procedure. I just downloaded the Numpy 1.4.0 tarball, and I succeeded in installing it. A program I wrote which depends on numpy ran successfully from SCIte. I'll move on to matplotlib and biopython next. I also succeeded in running both the Python 2.6 and the Python 2.5 interpreters from the terminal prompt as you suggested. Not sure whether I'll need to play with .bashrc yet. -- http://mail.python.org/mailman/listinfo/python-list
Re: Symbols as parameters?
On Jan 25, 1:05 am, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Sun, 24 Jan 2010 10:11:07 -0800, George Sakkis wrote: Both in your example and by using a context manager, you can get away with not passing locals() explicitly by introspecting the stack frame. You say that as if it were less of an ugly hack than the locals() trick. But sys._getframe is a private implementation detail, so you're no better off. The client *is* better off in that he doesn't have to pass locals() to some magic decorator to achieve his goal; how this is implemented is a different issue. As for being an ugly hack, you may use inspect.stack () if the underscore in sys._getframe() makes you feel dirty. George -- http://mail.python.org/mailman/listinfo/python-list
Re: medians for degree measurements
On 2010-01-23 05:52 , Steven D'Aprano wrote: On Fri, 22 Jan 2010 22:09:54 -0800, Steve Howell wrote: On Jan 22, 5:12 pm, MRABpyt...@mrabarnett.plus.com wrote: Steve Howell wrote: I just saw the thread for medians, and it reminded me of a problem that I need to solve. We are writing some Python software for sailing, and we need to detect when we've departed from the median heading on the leg. Calculating arithmetic medians is straightforward, but compass bearings add a twist. [...] I like this implementation, and it would probably work 99.% of the time for my particular use case. The only (very contrived) edge case that I can think of is when you have 10 bearings to SSW, 10 bearings to SSE, and the two outliers are unfortunately in the NE and NW quadrants. It seems like the algorithm above would pick one of the outliers. The trouble is that median of angular measurements is not a meaningful concept. The median depends on the values being ordered, but angles can't be sensibly ordered. Which is larger, 1 degree north or 359 degrees? Is the midpoint between them 0 degree or 180 degree? Then don't define the median that way. Instead, define the median as the point that minimizes the sum of the absolute deviations of the data from that point (the L1 norm of the deviations, for those familiar with that terminology). For 1-D data on the real number line, that corresponds to sorting the data and taking the middle element (or the artithmetic mean of the middle two in the case of even-numbered data). My definition applies to other spaces, too, that don't have a total order attached to them including the space of angles. The circular median is a real, well-defined statistic that is used for exactly what the OP intends to use it for. The median of the number line 0= x= 360 is 180, but what's the median of the circle 0 deg= theta= 360 deg? With no end points, it's meaningless to talk about the middle. For this reason, I expect that taking the median of bearing measurements isn't well defined. You can probably get away with it so long as the bearings are close, where close itself is ill-defined. In any case, this isn't a programming problem, it's a mathematics problem. I think you're better off taking it to a maths or statistics forum, and see what they say. puts on statistics hat Same answer with my statistics hat on or off. :-) /puts on statistics hat -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: how to generate random numbers that satisfy certain distribution
On 2010-01-23 21:30 , Steven D'Aprano wrote: On Sat, 23 Jan 2010 14:10:10 -0800, Paul Rubin wrote: Steven D'Apranost...@remove-this-cybersource.com.au writes: The Box-Muller transform is reasonably simple, but you can't be serious that it is simpler than adding twelve random numbers and subtracting six! If you want a normal distribution, using the Box-Muller transform is simpler because it spares you the complication of figuring out whether the 12-trial binomial approximation is close enough to produce reliable results for your specific application, which you obviously have to do if you are using the approximation for anything serious. But using Box-Miller gives you the complication of figuring out whether you care about being thread safety, which you have to do if you're doing anything serious. (See the comments in the random module for the gauss method). If you care about thread-safety, each thread should get its own Random instance anyways. By the way, does anyone know why there is no Poisson random numbers in the module? The implementation is quite simple (but not as simple as the Linux kernel *wink*): def poisson(lambda_=1): L = math.exp(-lambda_) k = 0 p = 1 while 1: k += 1 p *= random.random() if p= L: break return k-1 although this can be improved upon for large values of lambda_. Where large is about 10. That's where my implementation in numpy.random switches over to a more complicated, but more efficient implementation. It does require a log-gamma special function implementation, though. #define LS2PI 0.91893853320467267 #define TWELFTH 0.0833 long rk_poisson_ptrs(rk_state *state, double lam) { long k; double U, V, slam, loglam, a, b, invalpha, vr, us; slam = sqrt(lam); loglam = log(lam); b = 0.931 + 2.53*slam; a = -0.059 + 0.02483*b; invalpha = 1.1239 + 1.1328/(b-3.4); vr = 0.9277 - 3.6224/(b-2); while (1) { U = rk_double(state) - 0.5; V = rk_double(state); us = 0.5 - fabs(U); k = (long)floor((2*a/us + b)*U + lam + 0.43); if ((us = 0.07) (V = vr)) { return k; } if ((k 0) || ((us 0.013) (V us))) { continue; } if ((log(V) + log(invalpha) - log(a/(us*us)+b)) = (-lam + k*loglam - loggam(k+1))) { return k; } } } -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: easy_install error ...
I am also having another issue with easy_install, python setup.py easy_install --find-links thirdparty 'docutils==0.4' running easy_install error: Not a URL, existing file, or requirement spec: 'docutils==0.4' I think both problem are related. I have setuptool version .6C11 install and I am running python 2.5 on window OS. Is any one else having similar issue with setuptool version .6C11? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Sikuli: the coolest Python project I have yet seen...
Sikuli is the coolest Python project I have ever seen in my ten year hobbyist career. An MIT oepn source project, Sikuli uses Python to automate GUI tasks (in any GUI or GUI baed app that runs the JVM) by simply drag and dropping GUI elements into Python scripts as function arguments. Download at http://sikuli.csail.mit.edu/ I also did this podcast about Sikuli http://media.libsyn.com/media/awaretek/Python411_20100124_Sikuli.mp3 -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Jan 24, 12:44 pm, Paul Rubin no.em...@nospam.invalid wrote: Steve Howell showel...@yahoo.com writes: Proposal: Improve list's implementation so that deleting elements from the front of the list does not require an O(N) memmove operation. ... It is possible now, of course, to use a data structure in Python that has O(1) for deleting off the top of the list, but none of the alternatives fully replicate the benefits of list itself. I think you are mostly referring to deque. Why don't you instead say what you think is wrong with using deque, and how deque can be improved? There is nothing wrong with deque, at least as far as I know, if the data strucure actually applies to your use case. It does not apply to my use case. See above. An implementation of this PEP would not change the definition of the language in any way, but it would have to minimally impact the performance of lists for the normal use cases. But you're talking about adding one or two words to EVERY list, and many normal use cases allocate a LOT of lists. Those use cases are likely more common than use cases that pop from the front of the list but for some reason can't use deque. For EVERY list, you are not only allocating memory for the list itself, but you are also allocating memory for the objects within the list. So the extra one or two words are NEGLIGIBLE. The most ambitious proposal is to fix the memory manager itself to allow the release of memory from the start of the chunk. That's inappropriate given the memory fragmentation it would cause. Bullshit. Memory managers consolidate free memory chunks all the time. That's their job. Really, you're describing a problem that arises in a few programs but up til now, as far as I know, everyone has found deque to be an adequate solution. Wrong. Many programs delete the first element of the list. Your approach of snarling against list is not persuading anyone that list needs to be changed, because most everyone is satisfied with the existing solution. Please provide evidence of that. I am pretty sure that everybody who chooses alternatives to Python would disagree. You might change approaches and discuss deque, what's wrong with it, and whether it can be fixed. Getting a change approved for deque is probably much easier than getting one approved for list, just because nowhere near as many things depend on deque's performance. Again...I am not looking to improve deque, which is a perfectly valid data structure for a limited set of problems. And when discussing performance in this contextc additive constants do matter. Wrong again. Operations that mutate lists are already expensive, and a few checks to see if unreleased memory can be reclaimed are totally NEGLIGIBLE. -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
On Sun, 24 Jan 2010 20:12:11 -0800, Steve Howell wrote: The most ambitious proposal is to fix the memory manager itself to allow the release of memory from the start of the chunk. That's inappropriate given the memory fragmentation it would cause. Bullshit. Memory managers consolidate free memory chunks all the time. That's their job. So let me get this straight... You've complained that Python's list.pop(0) is lame because it moves memory around. And your solution to that is to have the memory manager move the memory around instead? Perhaps I'm missing something, but I don't see the advantage here. At best, you consolidate all those moves you wanted to avoid and do them all at once instead of a few at a time. At worst, you get a situation where the application periodically, and unpredictably, grinds to a halt while the memory manager tries to defrag all those lists. Really, you're describing a problem that arises in a few programs but up til now, as far as I know, everyone has found deque to be an adequate solution. Wrong. Many programs delete the first element of the list. I'm sure they do. Many programs do all sorts of things, of varying sensibleness. But I'm pretty sure I've never written a program that deleted the first element of a list. Even if I have, it's a vanishingly small use-case for me. YMMV. Your approach of snarling against list is not persuading anyone that list needs to be changed, because most everyone is satisfied with the existing solution. Please provide evidence of that. I am pretty sure that everybody who chooses alternatives to Python would disagree. Do you honestly believe that everybody who prefers another language over Python does so because they dislike the performance of list.pop(0)? You might change approaches and discuss deque, what's wrong with it, and whether it can be fixed. Getting a change approved for deque is probably much easier than getting one approved for list, just because nowhere near as many things depend on deque's performance. Again...I am not looking to improve deque, which is a perfectly valid data structure for a limited set of problems. And when discussing performance in this contextc additive constants do matter. Wrong again. Operations that mutate lists are already expensive, and a few checks to see if unreleased memory can be reclaimed are totally NEGLIGIBLE. Popping from the end of the list isn't expensive. Reversing lists is relatively cheap. In-place modifications are very cheap. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: [2.5.1.1/dictionary] Change sorting order?
Arnaud Delobelle arno...@googlemail.com writes: Gilles Ganault nos...@nospam.com writes: On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault nos...@nospam.com wrote: To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the next letter, eg. display the list from A...Zdigits the first time, then B...ZAdigits, etc. Thanks everyone for the great feedback. I ended up using - a list instead of a dictionary to hold the list of names - use the random library to pick a character from which to start listing names (simpler than saving the next letter into a file, and starting from this the next time the loop is gone through) For those interested, here's some working code: == import random connected = [_test,-test,0test,1test,Aa,Aab,Bb,B,Cc,Ccaa] connected.sort() #Fill list with non-duplicate first letter of all items characters=[] for name in connected: char = name[0] #if this character not in list, add to array if not char in characters: characters.append(char) characters = list(set(name[0] for name in connected)) #Pick a random character from which to start iterating index = random.randint(0,len(characters)-1) startch = characters[index] startch = random.choice(characters) print Will start from %s % startch #Go through list starting with items that start with 'starch', and rotate from beginning result = [name for name in connected if name[0] = startch] + [name for name in connected if name[0] startch] I forgot this line: result = sorted(connected, key=lambda name: name[0] startch) This takes advantage of the fact that timsort is stable. So you could do it like this, assuming connected is sorted: characters = list(set(name[0] for name in connected)) startch = random.choice(characters) result = sorted(connected, key=lambda name: name[0] startch) If connected is not sorted, you could replace the last line with: result = sorted(connected, key=lambda name: (name[0] startch, name)) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: list.pop(0) vs. collections.dequeue
Steve Howell showel...@yahoo.com writes: There is nothing wrong with deque, at least as far as I know, if the data strucure actually applies to your use case. It does not apply to my use case. You haven't explained why deque doesn't apply to your use case. Until a convincing explanation emerges, the sentiment you're creating seems to be what's wrong with that guy and why doesn't he just use deque?. So, why aren't you using deque? If deque somehow isn't adequate for your use case, maybe it can be improved. Your approach of snarling against list is not persuading anyone that list needs to be changed, because most everyone is satisfied with the existing solution. Please provide evidence of that. I am pretty sure that everybody who chooses alternatives to Python would disagree. I've heard of many reasons to choose alternatives to Python, and have chosen alternatives to Python in various situations myself. The list.pop(0) issue has never been one of those reasons for me or anyone else I know of to choose an alternative until you came along. Anyway, you're welcome to switch to another language; nobody's heart will be broken if you do that. I'd be interested to know which languages handle list.pop(0) the way you're proposing for Python. And when discussing performance in this context, additive constants do matter. Wrong again. Operations that mutate lists are already expensive I'm talking about memory consumption, which is part of Python's concept of performance. You're proposing adding a word or two to every list, with insufficient justification presented so far. Any such justification would have to include a clear and detailed explanation of why using deque is insufficient, so that would be a good place to start. On another note: the idea you're suggesting, while not yet 100% convincing, is not crazy, which is why people are willing to discuss it with you reasonably. But your confrontational style is making discussion unpleasant. Can you dial it back a little? Your current approach is perhaps leading you towards people's ignore lists. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sikuli: the coolest Python project I have yet seen...
On Jan 25, 11:18 am, Ron ursusmaxi...@gmail.com wrote: Sikuli is the coolest Python project I have ever seen in my ten year hobbyist career. An MIT oepn source project, Sikuli uses Python to automate GUI tasks (in any GUI or GUI baed app that runs the JVM) by simply drag and dropping GUI elements into Python scripts as function arguments. Download athttp://sikuli.csail.mit.edu/I also did this podcast about Sikulihttp://media.libsyn.com/media/awaretek/Python411_20100124_Sikuli.mp3 Wow , It look likes like better than autoIt !! Very impressed. -- http://mail.python.org/mailman/listinfo/python-list
[issue2611] Extend buildbot web interface to allow for forced tests to be run on a slave in verbose mode.
Martin v. Löwis mar...@v.loewis.de added the comment: I'm closing this as won't fix. If there is a need to run specific tests in specific ways, it is best to check in code that does it as desired. If it is then unacceptable to run that change on all slaves, a branch can be created, and building the branch can be triggered in the UI. -- resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2611 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7767] Add PyLong_AsLongLongAndOverflow
Changes by Mark Dickinson dicki...@gmail.com: -- assignee: - mark.dickinson nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7767 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7736] os.listdir hangs since opendir() and closedir() do not release GIL
Martin v. Löwis mar...@v.loewis.de added the comment: I think the bug here is really in the application, which makes a system call to fuse and the fuse callback in the same process. This isn't supported, and IMO doesn't need to be. Python makes no promises that it will accept callbacks while a system call is in progress. That said, working around this problem in this specific case with the proposed patch is fine with me. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7736 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7242] Forking in a thread raises RuntimeError
Martin v. Löwis mar...@v.loewis.de added the comment: One relevant difference may be the change to the fork semantics in Solaris 10: fork() now means the same as fork1(). Before, fork() meant the same as forkall(), unless the applications was linked with -lpthread, in which case fork() also meant fork1(). See fork(2). So I'd be curious if a) the test case passes on Solaris 8 if fork1 is being used, and b) whether it passes if you make sure -lpthread is being used. If so, I'd rather fix this issue by changing the linkage for Solaris 8 (or declaring that system as unsupported altogether), instead of fiddling yet again with the fork handling. In Python, posix.fork definitely needs to mean POSIX fork. If it's something else (i.e. the thread ID changes in Solaris 8 whether fork1 or forkall is used), then the patch is fine in principle. However, I would always reset the thread ID. In your patch, it is not clear why you apply this resetting to Solaris and AIX, but not other systems. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7242 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7633] decimal.py: type conversion in context methods
Mark Dickinson dicki...@gmail.com added the comment: Thanks for the latest patch! It's looking good, but I have a few comments: (1) It's not necessary to do an isinstance(a, Decimal) check before calling _convert_other, since _convert_other does that check anyway. It doesn't really harm either, but for consistency with the way the Decimal methods themselves are written, I think the isinstance check should be left out. (2) The error message that's produced when the Decimal operation returns NotImplemented is a bit strange: decimal.getcontext().add(2, 'bob') Traceback (most recent call last): File stdin, line 1, in module File /Users/dickinsm/python/svn/trunk/Lib/decimal.py, line 3869, in add raise TypeError(Unable to convert %s to Decimal % r) TypeError: Unable to convert NotImplemented to Decimal Presumably that '% r' should be '% b' instead. (3) It looks like Context.power is missing a NotImplemented check: decimal.getcontext().power(2, 'bob') NotImplemented (4) We should consider updating the documentation for the Context methods, though there's actually nothing there that would suggest that these operations wouldn't work for integers. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7633 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7633] decimal.py: type conversion in context methods
Mark Dickinson dicki...@gmail.com added the comment: One more: (5) The patch includes a (presumably accidental) change to the divmod docstring, from Return (a // b, a % b) to Return (self // other, self % other). I think the first version is preferable. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7633 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7633] decimal.py: type conversion in context methods
Mark Dickinson dicki...@gmail.com added the comment: And another. :) (6) I think that with these changes, the single argument methods, like Context.exp, and Context.sqrt, should also accept integers. Thoughts? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7633 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2531] float compared to decimal is silently incorrect.
Mark Dickinson dicki...@gmail.com added the comment: So here's the plan for trunk. The big question is: what should be done for py3k? For trunk: - all comparisons (==, !=, =, =, , ) between floats and Decimals return the correct numerical result, as though the float were converted to a Decimal with no loss of precision. Like-signed float and Decimal infinities compare equal. float and Decimal nans compare unequal to everything else, as always. - check whether anything special needs to be done to make sure that cmp also returns sensible results. - fix Decimal.__hash__ so that when x == y for a float x and Decimal instance y, hash(x) == hash(y) - the hash fix above is going to slow down hash computations, so consider caching hash values for Decimal instances (as a _hash attribute on the Decimal object itself). My gut feeling is that this probably isn't worth it, given that Decimal objects probably don't get hashed very often in normal use, but I'll do some timings to find out what the performance impact of the new hash is. For py3k, the obvious options are: (A) adopt the above changes, or (B) keep Decimal and float non-comparable (as currently). In this case, a Decimal-to-float comparison in trunk should probably raise a DeprecationWarning. (Note that DeprecationWarnings are now silent by default, so such a warning wouldn't impact end-users much.) -- priority: - high versions: +Python 3.2 -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2531 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7633] decimal.py: type conversion in context methods
Stefan Krah stefan-use...@bytereef.org added the comment: (6) Yes, I think that is logical. In cdecimal, I accept integers for all unary methods except is_canonical and number_class. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7633 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2531] float compared to decimal is silently incorrect.
Stefan Krah stefan-use...@bytereef.org added the comment: I'm new to this thread, so I hope I didn't miss anything that has been said already. I don't fully understand why TypeError cannot be raised in 2.x. The 2.6 documentation for tp_richcompare says: If you want to implement a type for which only a limited set of comparisons makes sense (e.g. == and !=, but not and friends), directly raise TypeError in the rich comparison function. I just tried that in the 2.7 version of cdecimal, and it works well: from cdecimal import * Decimal(9) 2.5 Traceback (most recent call last): File stdin, line 1, in module TypeError: conversion from float to Decimal is not supported -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2531 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com