Fast decimal arithmetic module released
[As requested, repost from comp.lang.python] Hi, today I have released the following packages for fast arbitrary precision decimal arithmetic: 1. libmpdec Libmpdec is a C (C++ ready) library for arbitrary precision decimal arithmetic. It is a complete implementation of Mike Cowlishaw's General Decimal Arithmetic specification. 2. fastdec.so == Fastdec.so is a Python C module with the same functionality as decimal.py. With some restrictions, code written for for decimal.py should work identically. 3. deccheck.py === deccheck.py performs redundant calculations using both decimal.py and fastdec.so. For each calculation the results of both modules are compared and an exception is raised if they differ. This module was mainly developed for testing, but could in principle be used for redundant calculations in general. Correctness Libmpdec passes IBM's official test suite and a multitude of additional tests. Fastdec.so passes (with minor modifications) all Python unit tests. When run directly, deccheck.py performs very exhaustive tests that compare fastdec.so with decimal.py. All tests complete successfully under Valgrind. Speed == In a couple of initial benchmarks, libmpdec compares very well against decNumber and the Intel decimal library. For very large numbers, the speed is roughly the same as the speed of the apfloat library. Fastdec.so compares quite well against gmpy and even native Python floats. In the benchmarks, it is significantly faster than Java's BigDecimal class. Portability All tests have been completed on Linux 64/32-bit, Windows 64/32-bit, OpenSolaris 32-bit, OpenBSD 32-bit and Debian Mips 32-bit. For 32-bit platforms there is a pure ANSI C version, 64 bit platforms require a couple of asm lines. Further information and downloads at: http://www.bytereef.org/libmpdec.html Stefan Krah -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Q: sort's key and cmp parameters
[Paul Rubin] The idea was that you have a list of trees that you want to sort, and an ordering relation between trees: def gt(tree1, tree2): ... where you recursively descend both trees until you find an unequal pair of nodes. You're not trying to sort the nodes within a single tree. Can you give an example of a list of trees and a cmp function that recursively compares them? Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
[Paul Rubin] The idea was that you have a list of trees that you want to sort, and an ordering relation between trees: def gt(tree1, tree2): ... Are the trees user defined classes? Can the gt() function be added incorporated as __lt__ method so that you can just run a plain sort: sort(list_of_trees) Is the recursive search order something you can turn into a straight sequence: sort(list_of_trees, key=flattener) IOW, if there is an ordering relation between the trees, why can't it be either part of the tree API or collapsable into a list of successive nodes to be compared. From the sound of it, the trees are static during the sort and would get a nice O(n log n) -- O(n) speed-up if a key function were allowed to flatten them in a single pass. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: Opinions, please, on PEP 8 and local, 3rd party imports
Philip Semanchuk phi...@semanchuk.com writes: Our project uses some libraries that were written by 3rd parties (i.e. not us). These libraries fit into a single Python file and live in our source tree alongside other modules we've written. Why in the same source tree? They are maintained separately, so you shouldn't be duplicating them in your source. When our app is distributed, they'll be included in the installation. That can be done simply by having the third-party's standard distribution included with yours, and use it *if it's not already installed* on the user's system. In other words, they're not prerequisites that we'll make the user install, and they won't live in site-packages. What if they already *do* exist in site-packages? Why not install them there yourself? PEP 8 http://www.python.org/dev/peps/pep-0008/ says the following: Imports should be grouped in the following order: 1. standard library imports 2. related third party imports 3. local application/library specific imports I'm not sure in which category to place local, 3rd-party modules like configobj. They are third-party imports; category 2. Clearly, they belong in category 3 since they're local. They shouldn't be local, since they're not part of your application's code base; they're maintained as separate distributions (even if you bundle them together when distributing your work). Moreover, if there is an update to configobj by its current maintainers, and I have installed three (or seven, or seventy-three) applications using it, I want *one* update into site-packages to fix it for *all* of those applications. Not have to fuss about with all the duplicated copies, and worry about which ones have been missed (or, worse, *not* worry and the be confused over why the bug is still occurring in some applications). Clearly, they also belong in category 2 since they're 3rd party modules, and explicitly labeling an imported module as this is code we didn't write is useful. But I've always reserved category 2 for external libraries (e.g. numpy, wxPython, Twisted, PIL, etc.). Third-party libraries *are* external libraries. Please, for the sake of your users, keep them so. You can *install* them at the same time, but please don't *duplicate* them, forking them as though they're part of your code base. -- \ “We are not gonna be great; we are not gonna be amazing; we are | `\ gonna be *amazingly* amazing!” —Zaphod Beeblebrox, _The | _o__)Hitch-Hiker's Guide To The Galaxy_, Douglas Adams | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Opinions, please, on PEP 8 and local, 3rd party imports
On Fri, 2009-10-02 at 20:22 -0400, Simon Forman wrote: 2.5 +1 I'd like to suggest 2.46 instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: Haskell's new logo, and the idiocy of tech geekers
Xah Lee wrote: Haskell has a new logo. A fantastic one. Beautiful. For creator, context, detail, see bottom of: What does this have to do with Python? Nothing. So why are you posting it to comp.lang.python? Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Opinions, please, on PEP 8 and local, 3rd party imports
On Oct 2, 9:50 pm, Philip Semanchuk phi...@semanchuk.com wrote: Hi all, PEP 8 http://www.python.org/dev/peps/pep-0008/ says the following: Imports should be grouped in the following order: 1. standard library imports 2. related third party imports 3. local application/library specific imports I'm not sure in which category to place local, 3rd-party modules like configobj. ... Clearly, the best choice is category 2.5? Actually 2.5 is doable :-) I translate it as just after any of 2 and before any of 3 Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Raymond Hettinger pyt...@rcn.com writes: Can you give an example of a list of trees and a cmp function that recursively compares them? Example of list of trees (nested dicts). In practice you could get such a list from the simplejson module: list_of_trees = [{'value':1, 'left':{'value':3,'left':None,'right':None}, 'right':{'value':7,'left':{'value':5, ...}}}, {'value':19, 'left':{'value':23', ...}}, ... ] Example comparison function: def compare(tree1, tree2): c = cmp(tree1['value'], tree2['value']) if c != 0: return c c = cmp(tree1['left'], tree2['left']) if c != 0: return c return cmp(tree1['right'], tree2['right]) Are the trees user defined classes? Not in general. They might be nested tuples, lists, or dictionaries. Or they could come from a non-extensible library-defined class, like from cElementTree. From the sound of it, the trees are static during the sort and would get a nice O(n log n) -- O(n) speed-up if a key function were allowed to flatten them in a single pass. But the key function has to do all those comparisons on the internal nodes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Paul Rubin http://phr...@nospam.invalid writes: Example comparison function: def compare(tree1, tree2): c = cmp(tree1['value'], tree2['value']) if c != 0: return c c = cmp(tree1['left'], tree2['left']) if c != 0: return c return cmp(tree1['right'], tree2['right]) Sorry, meant recursive comparison. def compare(tree1, tree2): c = cmp(tree1['value'], tree2['value']) if c != 0: return c c = compare(tree1['left'], tree2['left']) if c != 0: return c return compare(tree1['right'], tree2['right]) -- http://mail.python.org/mailman/listinfo/python-list
Trouble sending / receiving compressed data (using zlib) as HTTP POST to server (in django)
Hi, I am trying to send compressed data to a server written in django. But it shows error while decompressing the data in the server. After some experiment I found that the server is not receiving the exact data I am sending. data = 'hello, this is a test message this is another message' data = zlib.compress(data) # now it looks like: x��HQ(��,V�D���T�p^~IFjL�e # length is 45 in django (view) I receive it: data = request.POST['data'] # now it looks like: xQ(�,V�D���^~IFjL�e # length is 34 Can anybody help me understand the issue and how to get over? thanks, Subeen. http://love-python.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing your scripts, with plenty of re-use
bukzor wrote: I would assume that putting scripts into a folder with the aim of re- using pieces of them would be called a package, but since this is an anti-pattern according to Guido, apparently I'm wrong-headed here. (Reference: http://mail.python.org/pipermail/python-3000/2007-April/006793.html ) Say you have ~50 scripts or so with lots of re-use (importing from each other a lot) and you want to organize them into folders. How do you do this simply? Interesting question, ... ... and although I've a working situation, I would like to see other answers. In my situation I've an estimate of about 2000 scripts (in fact every script I ever wrote), with about zero redundancy. I still don't use (because I don't fully understand them) packages, but by trial and error I found a reasonable good working solution, with the following specifications - (Almost) any script (what ever it uses from one of the other scripts can run standalone - libraries that need another main program ( e.g. a grid component needs a GUI) can launch another main program to test itself - All __init__ files are generated automatically Although not containing the last ideas, here's an idea of what I do: http://mientki.ruhosting.nl/data_www/pylab_works/pw_importing.html cheers, Stef The intent is to have people be able to check out the directly from CVS and have the scripts just work, even if they're not directly on the PYTHONPATH. This seems to be the best discussion on the topic, but the conclusion seemed to be that there's no good way. That seems unthinkable considering python's dedication to simplicity and elegance. http://groups.google.com/group/comp.lang.python/browse_thread/thread/c44c769a72ca69fa/ It looks like I'm basically restating this post, which sadly got dropped without further comment: http://mail.python.org/pipermail/python-3000/2007-April/006814.html -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing your scripts, with plenty of re-use
On Fri, 02 Oct 2009 18:14:44 -0700, bukzor wrote: I would assume that putting scripts into a folder with the aim of re- using pieces of them would be called a package, A package is a special arrangement of folder + modules. To be a package, there must be a file called __init__.py in the folder, e.g.: parrot/ +-- __init__.py +-- feeding/ +-- __init__.py +-- eating.py +-- drinking.py +-- fighting.py +-- flying.py +-- sleeping.py +-- talking.py This defines a package called parrot which includes a sub-package feeding and modules fighting, flying, sleeping and talking. You can use it by any variant of the following: import parrot # loads parrot/__init__.py import parrot.talking # loads parrot/talking.py from parrot import sleeping import parrot.feeding from parrot.feeding.eating import eat_cracker and similar. Common (but not compulsory) behaviour is for parrot/__init__.py to import all the modules within the package, so that the caller can do this: import parrot parrot.feeding.give_cracker() without requiring to manually import sub-packages. The os module behaves similarly: having imported os, you can immediately use functions in os.path without an additional import. Just dumping a bunch of modules in a folder doesn't make it a package, it just makes it a bunch of modules in a folder. Unless that folder is in the PYTHONPATH, you won't be able to import the modules because Python doesn't look inside folders. The one exception is that it will look inside a folder for a __init__.py file, and if it finds one, it will treat that folder and its contents as a package. but since this is an anti-pattern according to Guido, apparently I'm wrong-headed here. (Reference: http://mail.python.org/pipermail/python-3000/2007-April/006793.html ) Guido's exact words were: The only use case seems to be running scripts that happen to be living inside a module's directory, which I've always seen as an antipattern. I'm not sure precisely what he means by that, because modules don't have directories, they are in directories. Perhaps he meant package. In that case, the anti-pattern according to Guido is not to put modules in a folder, but to have modules inside a package be executable scripts. To use the above example, if the user can make the following call from the shell: $ python ./parrot/talking.py polly want a cracker and have the module talking do something sensible, that's an anti- pattern. Modules inside a package aren't intended to be executable scripts called by the user. There should be one (or more) front-end scripts which are called by the user. Since they aren't intended to be imported, they can be anywhere, not just on the PYTHONPATH. But they import the modules in the package, and that package *is* in the PYTHONPATH. Using the above example, you would install the parrot folder and its contents somewhere on the PYTHONPATH, and then have a front-end script (say) talk-to-parrot somewhere else. Notice that the script doesn't even need to be a legal name for a module, since you're never importing it. Say you have ~50 scripts or so with lots of re-use (importing from each other a lot) and you want to organize them into folders. How do you do this simply? Of course you can have a flat hierarchy: one big folder, like the standard library, with a mixed back of very loosely connected modules: eating.py drinking.py feeding.py fighting.py flying.py parrot.py sleeping.py talking.py You can do that, of course, but it's a bit messy -- what if somebody installs parrot.py and eating.py, but not drinking.py, and as a consequence parrot.py fails to work correctly? Or what if the user already has a completely unrelated module talking.py? Chaos. The std library can get away with dumping (nearly) everything in the one directory, because it's managed chaos. Users aren't supposed to pick and choose which bits of the standard library get installed, or install other modules in the same location. Three alternatives are: * put your modules in a sub-folder, and tell the user to change the Python path to include your sub-folder, and hope they know what you're talking about; * put your modules in a package, tell the user to just place the entire package directory where they normally install Python code, and importing will just work; or * have each and every script manually manipulate the PYTHONPATH so that when the user calls that script, it adds its parent folder to the PYTHONPATH before importing what it needs. Messy and ugly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Calendar yr-mnth-day data to day since data
Hi all, I have some calendar data in three arrays corresponding to yr, month, day that I would like to convert to day since data and be consistent with changes in leap year. I've included a sample of the data structures below. Any suggestions??? Thanks in advance yr mnthday daySince 19701 1 1 19701 15 15 19701 28 28 19702 1 32 19702 27 59 19703 1 19703 4 19703 29 ... ...... 20081 1 20081 8 20081 25 20082 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Threaded GUI slowing method execution?
On 2 Okt, 21:30, Dave Angel da...@ieee.org wrote: There could very well be multiprocess support in wxPython. I'd check there first, before re-inventing the wheel. I don't think there is. But one can easily make a thread in the subprocess that polls a pipe and calls wx.PostEvent or wx.CallLater when something is received. I particularly like the Queue object in multiprocessing for this. One could also use win32api.SendMessage from pywin32 to send the event from one process to another. The parent must know the hwnd of the subprocess main wx.Frame. The subprocess gets that from calling the GetHandle() method of its wx.Frame, and must post it back to the parent, presumably via a pipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: re.sub do not replace portion of match
J Wolfe vorticitywo...@gmail.com wrote: Hi, Is there a way to flag re.sub not to replace a portion of the string? I have a very long string that I want to add two new line's to rather than one, but keep the value X: string = testX.\n.today -- note X is a value string = re.sub(testX.\n.,testX.\n\n., string) This just replaces X with the replacement string. Thanks, Jonathan Have you tried reading the documentation? http://www.python.org/doc/current/library/re.html#re.sub Backreferences, such as \6, are replaced with the substring matched by group 6 in the pattern. and more such options in the docs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Haskell's new logo, and the idiocy of tech geekers
http://blog.plover.com/prog/haskell/logo.html Oops... -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing your scripts, with plenty of re-use
On Sat, 03 Oct 2009 10:24:13 +0200, Stef Mientki wrote: I still don't use (because I don't fully understand them) packages, but by trial and error I found a reasonable good working solution, with the following specifications I find that fascinating. You haven't used packages because you don't understand them, but you've used another technique that you *also* don't understand well enough to generate a solution, and had to rely on trial and error. Packages are quite well documented. Since the alternative was trial-and- error on something you also don't fully understand, why did you avoid packages? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
The Python: Rag October issue available
The Python: Rag October issue available The October issue of The Python: Rag is available at: http://www.pythonrag.org A monthly, free, community run, Python magazine - issues are in pdf format, intended for anyone interested in Python, without being particularly serious. If you have anything you would like to say about Python, please contribute. -- http://mail.python.org/mailman/listinfo/python-list
re.sub do not replace portion of match
Hi, Is there a way to flag re.sub not to replace a portion of the string? I have a very long string that I want to add two new line's to rather than one, but keep the value X: string = testX.\n.today -- note X is a value string = re.sub(testX.\n.,testX.\n\n., string) This just replaces X with the replacement string. Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing your scripts, with plenty of re-use
Great description - wish the Python docs could be as clear. Thanks. \d -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Paul Rubin http://phr...@nospam.invalid writes: c = compare(tree1['left'], tree2['left']) Of course this recursive call crashes if either branch is None. Oh well, I'll stop trying to correct it since I'm sure you get the idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode text file
On Sep 27, 6:39 pm, Mark Tolonen metolone+gm...@gmail.com wrote: Junaid junu...@gmail.com wrote in message news:0267bef9-9548-4c43-bcdf-b624350c8...@p23g2000vbl.googlegroups.com... I want to do replacements in a utf-8 text file. example f=open(test.txt,r) #this file is uft-8 encoded raw = f.read() txt = raw.decode(utf-8) You can use the codecs module to open and decode the file in one step txt.replace{'English', ur'ഇംഗ്ലീഷ്') #replacing raw unicode string, but not working The replace method returns the altered string. It does not modify it in place. You also should use Unicode strings for both the arguments (although it doesn't matter in this case). Using a raw Unicode string is also unnecessary in this case. txt = txt.replace(u'English', u'ഇംഗ്ലീഷ്') f.write(txt) You opened the file for writing. You'll need to close the file and reopen it for writing. f.close() f.flush() Flush isn't required. close() will flush. Also to have text like ഇംഗ്ലീഷ് in a file you'll need to declare the encoding of the file at the top and be sure to actually save the file in the encoding. In summary: # coding: utf-8 import codecs f = codecs.open('test.txt','r','utf-8') txt = f.read() txt = txt.replace(u'English', u'ഇംഗ്ലീഷ്') f.close() f = codecs.open('test.txt','w','utf-8') f.write(txt) f.close() -Mark thanx everyone for replying, I did as Mark suggested, and it worked :) thanx once more -- http://mail.python.org/mailman/listinfo/python-list
Re: Haskell's new logo, and the idiocy of tech geekers
2009/10/3 Xah Lee xah...@gmail.com: for my criticism or comment on logos, typical response by these people are showcases of complete ignorance of social function of logos [snip and rearrange] discussed now and then in these communities often without my involvement. “you are a fucking idiot... motherfucking aggresive it's just few of priest fuckheads look at lojban's motherfucking idiotic logo If you really knew anything about social function you would be able to work out why people think you are a troll. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sending / receiving compressed data (using zlib) as HTTP POST to server (in django)
subeen tamim.shahr...@gmail.com (s) wrote: s Hi, s I am trying to send compressed data to a server written in django. But s it shows error while decompressing the data in the server. After some s experiment I found that the server is not receiving the exact data I s am sending. s data = 'hello, this is a test message this is another message' s data = zlib.compress(data) s # now it looks like: x��HQ(��,V�D.���T�p^~IFj.L.�.e s # length is 45 Note: you can't just paste binary data in the message and expect something sensible. Better use the result of 'print data'. s in django (view) I receive it: s data = request.POST['data'] s # now it looks like: xQ(�,V�D���.^~IFj.L.�.e s # length is 34 s Can anybody help me understand the issue and how to get over? How did you post the data? If you post binary data you should indicate this with a proper mime type, like application/octet-stream. Otherwise it might be interpreted as text which it isn't. -- Piet van Oostrum p...@vanoostrum.org WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- http://mail.python.org/mailman/listinfo/python-list
Re: Calendar yr-mnth-day data to day since data
skorpi...@gmail.com skorpi...@gmail.com (sc) wrote: sc Hi all, sc I have some calendar data in three arrays corresponding to yr, month, sc day that I would like to convert to day since data and be consistent sc with changes in leap year. I've included a sample of the data sc structures below. Any suggestions??? Thanks in advance sc yr mnthday daySince sc 19701 1 1 sc 19701 15 15 sc 19701 28 28 sc 19702 1 sc 32 sc 19702 27 59 sc 19703 1 sc 19703 4 sc 19703 29 sc ... ...... sc 20081 1 sc 20081 8 sc 20081 25 sc 20082 1 Days since what? It appears here to be since 1969-12-31, or since 1970-1-1 but then starting with 1 instead of 0. And your 59 is wrong if the others are deemed to be correct. Depending on what you want you have to add 1 to the following solution import datetime startdate = datetime.date(1970, 1, 1) enddate = datetime.date(1970,3,1) timediff = enddate - startdate print timediff.days result: 59 -- Piet van Oostrum p...@vanoostrum.org WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast decimal arithmetic module released
Mark Dickinson dicki...@gmail.com wrote: On Oct 2, 8:53 pm, Stefan Krah stefan-use...@bytereef.org wrote: Hi, today I have released the following packages for fast arbitrary precision decimal arithmetic: [...] Nice! I'd been wondering how you'd been finding all those decimal.py bugs. Now I know. :) Thanks! Yes, actually deccheck.py deserves the credit. ;) Stefan Krah -- http://mail.python.org/mailman/listinfo/python-list
Need feedback on subprocess-using function
I'm relatively new to Python, and I'm trying to get the hang of using Python's subprocess module. As an exercise, I wrote the Tac class below, which can prints output to a file in reverse order, by piping it through the Unix tac utility. (The idea is to delegate the problem of managing the memory for an arbitrarily large task to tac.) class Tac(object): def __init__(self, path): out = open(path, 'w') self.pipe = subprocess.Popen(['tac'], stdout=out, stdin=subprocess.PIPE, stderr=subprocess.PIPE) def prn(self, string): try: self.pipe.stdin.write('%s\n' % string) except: self.close() raise def close(self): p = self.pipe p.stdin.close() err = p.stderr.read() if err: raise OSError(err) This works OK, as far as I can tell, but I'm not sure that I've dotted all the i's and crossed all the t's... E.g., I had to add the line p.stdin.close() to the close method when I when I ran into sporadic deadlock at the p.stderr.read() statement. Are there other similar problems lurking in this code? Also, there's no robust mechanism for invoking this close method in case of an exception (unless the exception happens during the execution of prn). Any comments and suggestions would be greatly appreciated. G -- http://mail.python.org/mailman/listinfo/python-list
Re: Haskell's new logo, and the idiocy of tech geekers
On 3 Oct, 00:33, Xah Lee xah...@gmail.com wrote: Haskell has a new logo. A fantastic one. Beautiful. For creator, context, detail, see bottom of: • A Lambda Logo Tour http://xahlee.org/UnixResource_dir/lambda_logo.html I'm amazed he thinks anyone would donate 3 USD to that site -- http://mail.python.org/mailman/listinfo/python-list
Enormous Input and Output Test
Hi, py.folk! I need your help to understand how http://www.spoj.pl/problems/INOUTEST/ can be passed in Python. I see two guys who managed to get accepted: http://www.spoj.pl/ranks/INOUTEST/lang=PYTH My code for this is: === import psyco psyco.full() import sys def noo(b): b = b.split() return str(int(b[0]) * int(b[1])) + '\n' def foo(): ##sys.stdin = open('D:/1583.txt', 'rt') a = sys.stdin.readlines() a = a[1:int(a[0]) + 1] a = map(noo, a) sys.stdout.writelines(a) foo() === But it gets Time Limit Exceeded verdict. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: setuptools, accessing ressource files
On Oct 2, 7:04 am, Patrick Sabin patrick.just4...@gmail.com wrote: I use setuptools to create a package. In this package I included some images and I checked that they are in the egg-file. The problem is how can I access the images in the package? I tried pkgutil.get_data, but only got an IOError, because the EGG-INFO directory doesn't exist. I tried pkg_resources.get_distribution('dist').get_metadata('images/image.png') with a similar error (IOError) What is the best way to access images distributed in an egg file? The resource_stream(), resource_string(), or resource_filename() functions: http://peak.telecommunity.com/DevCenter/PkgResources#basic-resource-access -Patrick -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular expression to structure HTML
On Oct 2, 11:14 pm, greg g...@cosc.canterbury.ac.nz wrote: Brian D wrote: This isn't merely a question of knowing when to use the right tool. It's a question about how to become a better developer using regular expressions. It could be said that if you want to learn how to use a hammer, it's better to practise on nails rather than screws. -- Greg It could be said that the bandwidth in technical forums should be reserved for on-topic exchanges, not flaming intelligent people who might have something to contribute to the forum. The truth is, I found a solution where others were ostensibly either too lazy to attempt, or too eager grandstanding their superiority to assist. Who knows -- maybe I'll provide an alternative to BeautifulSoup one day. -- http://mail.python.org/mailman/listinfo/python-list
Customizing Option Elements
Hi; I want to create option elements within a select element in which I could insert html, which, of course, is illegal (don't tell the police ;) so I'm looking at recreating the form elements using my own customized elements, that is, hacking the equivalent from scratch, but how do I proceed? I would like to make blocks of color using 6-digit rgb codes (#ff) with verbiage. How proceed? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
In 7xtyyhikrl@ruckus.brouhaha.com Paul Rubin http://phr...@nospam.invalid writes: Python 2.x provides two ways and you can use whichever one fits the application better. I have never understood why Python 3.x finds it necessary to break one of them. Maybe I can migrate to Haskell by the time Python 2.x becomes deprecated. !!! Maybe Haskell is much handier than I give it credit for, but it's hard for me to imagine that it is as convenient as Python 3, even without the cmp sort option... (And I agree with you that getting rid of sort's cmp in Python 3 was a bad idea.) What's going on here? Our lab recently hired a new postdoc who, to our disbelief, works almost exclusively in OCaml. And I hear all this talk about switching to Haskell or Scheme. I don't get it. Despite the elegance of these languages, the libraries are not there. It seems to me it would take forever to get the simplest things done in these languages... Confused. kj -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python: Rag October issue available
On Fri, 02 Oct 2009 11:32:41 -0700, steven.oldner wrote: Hi, no -its just put on the website. Unless there's a method you can suggest? Cheers Bernie On Oct 2, 11:14 am, Bernie edi...@pythonrag.org wrote: The Python: Rag October issue available The October issue of The Python: Rag is available at: http://www.pythonrag.org A monthly, free, community run, Python magazine - issues are in pdf format, intended for anyone interested in Python, without being particularly serious. If you have anything you would like to say about Python, please contribute. Thanks! Any way to subscribe to it? -- http://mail.python.org/mailman/listinfo/python-list
Re: AJAX Widget Framework
Laszlo Nagy wrote: I'm looking for an open source, AJAX based widget/windowing framework. Here is what I need: - end user opens up a browser, points it to a URL, logs in - on the server site, sits my application, creating a new session for each user that is logged in - on the server site, I create windows(frames), put widgets on them, write event handlers etc. Just like with wx or pygtk. - However, windows are created in the user's browser, and events are triggered by Javascript, and sent back to server through AJAX. - the server side would be - of course - written in Python. I was looking these projects: http://www.uize.com/ http://pyjs.org/ There are many frameworks listed here which I did not check: http://internetmindmap.com/javascript_frameworks. I have no idea which has Python support, and probably there are only a few that worth looking at. I wonder if you could tell me which are the pros and contras for these frameworks. If there is a comparison available on the NET, pointing me to the right URL would help a lot. The bottom line... My main goal is to develop enterprise class OLTP database applications. I'll need grid widget to display data in tabular format, and I'll use events heavily for data manipulation, live search, tooltips etc. I'm familiar with wxWidgets, pygtk and other toolkits, but not with AJAX. I have never used a system like that. Of course I don't know which is the right way for you. I'm very happy with pyjamas. It allows you the create client applications in the same manner as standalone toolkits like wxWidgets. The message passing between client and server is simple done by exchanging json strings (its ajax based of course, but this stuff works silently in the background). On the server side there are many python toolkits, I prefer cherrypy, others are django and web.py. Hope this helps you. Mathias -- http://mail.python.org/mailman/listinfo/python-list
PIL : How to write array to image ???
Dear group I'm trying to use PIL to write an array (a NumPy array to be exact) to an image. Peace of cake, but it comes out looking strange. I use the below mini code, that I wrote for the purpose. The print of a looks like expected: [[ 200. 200. 200. ...,0.0.0.] [ 200. 200. 200. ...,0.0.0.] [ 200. 200. 200. ...,0.0.0.] ..., [ 0.0.0. ..., 200. 200. 200.] [ 0.0.0. ..., 200. 200. 200.] [ 0.0.0. ..., 200. 200. 200.]] But the image looks nothing like that. Please see the images on: http://hvidberg.net/Martin/temp/quat_col.png http://hvidberg.net/Martin/temp/quat_bw.png or run the code to see them locally. Please – what do I do wrong in the PIL part ??? :-? Martin import numpy as np from PIL import Image from PIL import ImageOps maxcol = 100 maxrow = 100 a = np.zeros((maxcol,maxrow),float) for i in range(maxcol): for j in range(maxrow): if (i(maxcol/2) and j(maxrow/2)) or (i=(maxcol/2) and j= (maxrow/2)): a[i,j] = 200 else: a[i,j] = 0 print a pilImage = Image.fromarray(a,'RGB') pilImage.save('quat_col.png') pilImage = ImageOps.grayscale(pilImage) pilImage.save('quat_bw.png') -- http://mail.python.org/mailman/listinfo/python-list
Re: Haskell's new logo, and the idiocy of tech geekers
It's Xah Lee, he's been trolling this and every other programing language group for over 10 years (preferably all at once). Let it go. On Sat, Oct 3, 2009 at 2:53 AM, Chris Withers ch...@simplistix.co.uk wrote: Xah Lee wrote: Haskell has a new logo. A fantastic one. Beautiful. For creator, context, detail, see bottom of: What does this have to do with Python? Nothing. So why are you posting it to comp.lang.python? Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
kj no.em...@please.post writes: !!! Maybe Haskell is much handier than I give it credit for, but it's hard for me to imagine that it is as convenient as Python 3, even without the cmp sort option... Heh, yeah, I was being a bit snarky/grouchy. Haskell has a very steep learning curve and will never be as convenient as Python for banging out some small script. It's worth considering for larger or more serious programs. What's going on here? Our lab recently hired a new postdoc who, to our disbelief, works almost exclusively in OCaml. And I hear all this talk about switching to Haskell or Scheme. I don't get it. Despite the elegance of these languages, the libraries are not there. It seems to me it would take forever to get the simplest things done in these languages... Haskell's library is growing very rapidly, more so than Python's I'd say. Take a look at http://donsbot.wordpress.com/2009/03/16/visualising-the-haskell-universe/ if you're willing to count Hackage (sort of the equivalent of the Python cheese shop). The Haskell Platform (counterpart to Python stdlib) is also very actively expanding. Ocaml and Scheme both seem to me to be sort of stagnant. Scheme is an elegant fossil. Some people find Ocaml to be at a sweet spot, combining Python's convenience and the more important aspects of Haskell's expressiveness. I haven't used it myself. It seems to me that Haskell is attracting all the most advanced development attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python resident memory retention Evan Jones' improvements
On Oct 2, 4:47 pm, Andrew MacIntyre andy...@bullseye.apana.org.au wrote: There are two things you need to be aware of in this situation: - not all Python's memory is allocated through Python's specialised malloc() - int and float objects in particular (in 2.x at least) are allocated directly via a privately managed free list, and any allocation requiring more than 256 bytes is directed to the platform malloc(). Any memory not allocated via Python's malloc() is not subject to the memory release facility referred to above. Python 2.6 does improve the management of memory consumed by int and float objects via the garbage collector. - while Python attempts to maximally utilise memory arenas to improve the chances of being able to free them, Python's malloc() does not do any compaction of memory (ie moving allocations between arenas) within existing arenas. Nor does garbage collection do this. So fragmented allocations can cause the retention of nearly empty arenas. I suspect that what you see with the second test script above is caused by some sort of fragmentation. Thank you for the explanation. Since my real application uses many small objects, it makes sense that memory cannot be reclaimed in the absence of compaction. Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL : How to write array to image ???
Martin wrote: Dear group I'm trying to use PIL to write an array (a NumPy array to be exact) to an image. Peace of cake, but it comes out looking strange. I use the below mini code, that I wrote for the purpose. The print of a looks like expected: [[ 200. 200. 200. ...,0.0.0.] [ 200. 200. 200. ...,0.0.0.] [ 200. 200. 200. ...,0.0.0.] ..., [ 0.0.0. ..., 200. 200. 200.] [ 0.0.0. ..., 200. 200. 200.] [ 0.0.0. ..., 200. 200. 200.]] But the image looks nothing like that. Please see the images on: http://hvidberg.net/Martin/temp/quat_col.png http://hvidberg.net/Martin/temp/quat_bw.png or run the code to see them locally. Please – what do I do wrong in the PIL part ??? :-? Martin import numpy as np from PIL import Image from PIL import ImageOps maxcol = 100 maxrow = 100 a = np.zeros((maxcol,maxrow),float) for i in range(maxcol): for j in range(maxrow): if (i(maxcol/2) and j(maxrow/2)) or (i=(maxcol/2) and j= (maxrow/2)): a[i,j] = 200 else: a[i,j] = 0 print a pilImage = Image.fromarray(a,'RGB') You are telling it the wrong mode information. If you want an RGB image, you need to give it a uint8 array with shape (height, width, 3). Exactly what are you trying to do? I can't infer that from your code. -- 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: Customizing Option Elements
I want to create option elements within a select element in which I could insert html, which, of course, is illegal (don't tell the police ;) so I'm looking at recreating the form elements using my own customized elements, that is, hacking the equivalent from scratch, but how do I proceed? I would like to make blocks of color using 6-digit rgb codes (#ff) with verbiage. How proceed? That are your requirements? If the only requirement is that it should look very very fancy and futuristic then you can do it with flash programming. (You need Flash knowledge and the result may not be a real select but an object.) Another way to do it is JavaScript and absolute positioned DOM elements (you will need CSS and JavaScript knowledge). One thing is sure: this question has almost nothing to do with Python. Please post this to a JavaScript or Flash programming mailing list. Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL : How to write array to image ???
Martin wrote: Dear group I'm trying to use PIL to write an array (a NumPy array to be exact) to an image. Peace of cake, but it comes out looking strange. I use the below mini code, that I wrote for the purpose. The print of a looks like expected: [[ 200. 200. 200. ...,0.0.0.] [ 200. 200. 200. ...,0.0.0.] [ 200. 200. 200. ...,0.0.0.] ..., [ 0.0.0. ..., 200. 200. 200.] [ 0.0.0. ..., 200. 200. 200.] [ 0.0.0. ..., 200. 200. 200.]] But the image looks nothing like that. Please see the images on: http://hvidberg.net/Martin/temp/quat_col.png http://hvidberg.net/Martin/temp/quat_bw.png or run the code to see them locally. Please – what do I do wrong in the PIL part ??? :-? Martin import numpy as np from PIL import Image from PIL import ImageOps maxcol = 100 maxrow = 100 a = np.zeros((maxcol,maxrow),float) for i in range(maxcol): for j in range(maxrow): if (i(maxcol/2) and j(maxrow/2)) or (i=(maxcol/2) and j= (maxrow/2)): a[i,j] = 200 else: a[i,j] = 0 print a pilImage = Image.fromarray(a,'RGB') pilImage.save('quat_col.png') pilImage = ImageOps.grayscale(pilImage) pilImage.save('quat_bw.png') The PIL seems to copy the array contents directly from memory without any conversions or sanity check. In your example The float values determine the gray value of 8 consecutive pixels. If you want a[i,j] to become the color of the pixel (i, j) you have to use an array with a memory layout that is compatible to the Image. Here are a few examples: import numpy from PIL import Image a = numpy.zeros((100, 100), numpy.uint8) a[:50, :50] = a[50:, 50:] = 255 Image.fromarray(a).save(tmp1.png) b = numpy.zeros((100, 100, 3), numpy.uint8) b[:50, :50, :] = b[50:, 50:, :] = [255, 0, 0] Image.fromarray(b).save(tmp2.png) c = numpy.zeros((100, 100), numpy.uint32) c[:50, :50] = c[50:, 50:] = 0xff808000 Image.fromarray(c, RGBA).save(tmp3.png) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: question about the GC implementation
On Oct 2, 11:20 am, Francis Moreau francis.m...@gmail.com wrote: Hello, I'm looking at gcmodule.c and in move_unreachable() function, the code assumes that if an object has its gc.gc_refs stuff to 0 then it *may* be unreachable. How can an object tagged as unreachable could suddenly become reachable later ? Thanks It looks like you're not reading through all of the comments: GC_TENTATIVELY_UNREACHABLE move_unreachable() then moves objects not reachable (whether directly or indirectly) from outside the generation into an unreachable set. Objects that are found to be reachable have gc_refs set to GC_REACHABLE again. Objects that are found to be unreachable have gc_refs set to GC_TENTATIVELY_UNREACHABLE. It's tentatively because the pass doing this can't be sure until it ends, and GC_TENTATIVELY_UNREACHABLE may transition back to GC_REACHABLE. Only objects with GC_TENTATIVELY_UNREACHABLE still set are candidates for collection. If it's decided not to collect such an object (e.g., it has a __del__ method), its gc_refs is restored to GC_REACHABLE again. -- http://mail.python.org/mailman/listinfo/python-list
Is pythonic version of scanf() or sscanf() planned?
Hi I know that in python, we can do the same with regexps or *.split()*, but thats longer and less practical method than *scanf()*. I also found that ( http://code.activestate.com/recipes/502213/ ), but the code doesn't looks so simple for beginners. So, whether it is or has been planned the core Python implementation of *scanf()* ? (prefered as a batteries included method) Thanks for any helpful answers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary with Lists
Hi, Shaun wrote: I'm trying to create a dictionary with lists as the value for each key. I was looking for the most elegant way of doing it... from collections import defaultdict d = defaultdict(list) d[joe].append(something) d[joe].append(another) d[jim].append(slow down, grasshopper) print d HTH, mick. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary with Lists
Shaun wrote: testDict = {} ... testDict [1] = testDict.get (1, []).append (Test0) # 1 does not exist, create empty array print testDict testDict [1] = testDict.get (1, []).append (Test1) print testDict [ ... ] However, the first printout gives {1: None} instead of the desired {1: ['test']}. What's wrong with this syntax? The trouble is that the list.append method returns None, after modifying the value of the parent list in place. So of course, None gets assigned to testDict[1] after the valuable work has been done. The old way to do what you want is testDict.setdefault (1, []).append (Test0) The new way is to inherit from defaultdict. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is pythonic version of scanf() or sscanf() planned?
ryniek90 wrote: Hi I know that in python, we can do the same with regexps or *.split()*, but thats longer and less practical method than *scanf()*. I also found that ( http://code.activestate.com/recipes/502213/ ), but the code doesn't looks so simple for beginners. So, whether it is or has been planned the core Python implementation of *scanf()* ? (prefered as a batteries included method) scanf() uses '%' format like that used for printing, but '%' format is being replaced in Python by '{}' format, so shouldn't any possible future scanf() use that instead? :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On Sat, Oct 3, 2009 at 6:54 AM, n00m n...@narod.ru wrote: Hi, py.folk! I need your help to understand how http://www.spoj.pl/problems/INOUTEST/ can be passed in Python. snip def foo(): ##sys.stdin = open('D:/1583.txt', 'rt') a = sys.stdin.readlines() That line is probably a Very Bad Idea (TM) as it reads the *entire* enormous file into memory *at once*. It would probably be much better to iterate over the file, thus only reading one individual line at a time. I'm betting the massive malloc()ing involved with .readlines() is a large part of the slowness. snip But it gets Time Limit Exceeded verdict. Any ideas? Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
n00m wrote: Hi, py.folk! I need your help to understand how http://www.spoj.pl/problems/INOUTEST/ can be passed in Python. I see two guys who managed to get accepted: http://www.spoj.pl/ranks/INOUTEST/lang=PYTH My code for this is: === import psyco psyco.full() import sys def noo(b): b = b.split() return str(int(b[0]) * int(b[1])) + '\n' def foo(): ##sys.stdin = open('D:/1583.txt', 'rt') a = sys.stdin.readlines() a = a[1:int(a[0]) + 1] a = map(noo, a) sys.stdout.writelines(a) foo() === But it gets Time Limit Exceeded verdict. Any ideas? Don't waste your time with problem sites that judge raw-clock time over (and before) accuracy, thereby greatly favoring low-level languages and hack tricks over clear high-level code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Haskell's new logo, and the idiocy of tech geekers
On Oct 2, 7:33 pm, Xah Lee xah...@gmail.com wrote: Haskell has a new logo. A fantastic one. Beautiful. For creator, context, detail, see bottom of: • A Lambda Logo Tour http://xahlee.org/UnixResource_dir/lambda_logo.html Interesting.. rant. Thanks for the logo collection, though, some of them are visually quite breathtaking. Q1: if you argue that Lisp and Scheme implementations are not purely functional enough to merit the use of the lambda character, then surely you'd be happy with the new Chicken logos, as the stylized representation is less obvious? Q2: if you preach about the sanctity of Greek characters, then what does your use of the sigma character mean -- that your site is a summation of all knowledge? Regards, -- Michel -- http://mail.python.org/mailman/listinfo/python-list
Problem with subprocess module on Windows with open file in append mode
When I run this little test program on Linux: import subprocess subprocess.call([python,-V], stderr=open(log.tmp,a)) the file log.tmp is appended to each time I run it. When I run it on Windows, however, the file log.tmp gets overwritten each time I run it. Though I can make it append on Windows like this: import os import subprocess f = open(log.tmp, a) f.seek(0, os.SEEK_END) subprocess.call([python,-V], stderr=f) I don't understand why that should be necessary. Is this a Python/subprocess bug on Windows? (I tested with Python 2.5.1 and Python 2.6.2 on Windows XP SP2). Thanks, /-\ __ Get more done like never before with Yahoo!7 Mail. Learn more: http://au.overview.mail.yahoo.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Calendar yr-mnth-day data to day since data
On Oct 3, 6:35 am, Piet van Oostrum p...@cs.uu.nl wrote: skorpi...@gmail.com skorpi...@gmail.com (sc) wrote: sc Hi all, sc I have some calendar data in three arrays corresponding to yr, month, sc day that I would like to convert to day since data and be consistent sc with changes in leap year. I've included a sample of the data sc structures below. Any suggestions??? Thanks in advance sc yr mnth day daySince sc 1970 1 1 1 sc 1970 1 15 15 sc 1970 1 28 28 sc 1970 2 1 sc 32 sc 1970 2 27 59 sc 1970 3 1 sc 1970 3 4 sc 1970 3 29 sc ... ... ... sc 2008 1 1 sc 2008 1 8 sc 2008 1 25 sc 2008 2 1 Days since what? It appears here to be since 1969-12-31, or since 1970-1-1 but then starting with 1 instead of 0. And your 59 is wrong if the others are deemed to be correct. Depending on what you want you have to add 1 to the following solution import datetime startdate = datetime.date(1970, 1, 1) enddate = datetime.date(1970,3,1) timediff = enddate - startdate print timediff.days result: 59 -- Piet van Oostrum p...@vanoostrum.org WWW:http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Thanks ... This module does the trick nicely -- http://mail.python.org/mailman/listinfo/python-list
Re: Is pythonic version of scanf() or sscanf() planned?
On 2009-10-03, ryniek90 rynie...@gmail.com wrote: So, whether it is or has been planned the core Python implementation of *scanf()* ? One of the fist things I remember being taught as a C progrmmer was to never use scanf. Programs that use scanf tend to fail in rather spectacular ways when presented with simple typos and other forms of unexpected input. Given the bad behavior and general fragility of scanf(), I doubt there's much demand for something equally broken for Python. Thanks for any helpful answers. Not sure if mine was helpful... -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On Oct 4, 2:29 am, Chris Rebert c...@rebertia.com wrote: That line is probably a Very Bad Idea (TM) as it reads the *entire* enormous file into memory *at once*. It would probably be much better to iterate over the file, thus only reading one individual line at a time. I'm betting the massive malloc()ing involved with .readlines() is a large part of the slowness. Certainly not. The culprit is line a = map(noo, a). Without it execution time = 2.59s (I've just checked it). -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
PS Time Limit for this problem = 20s -- http://mail.python.org/mailman/listinfo/python-list
Identify runs in list
Hi all, I have a data structure in a list as in: [0 0 0 3 0 5 0 0 0 0 1 0 4 0 5 0 0 7 0 0 0 0 0 12 0 0 4] I would like to extract three list from this data: 1) runsOfZero: [3 4 5] 2) runsOfNonZero: [3 8 4] 3) SumOfRunsOfNonZero: [8 17 16] Any suggestions would be appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: Identify runs in list
On Sat, Oct 3, 2009 at 7:21 PM, skorpi...@gmail.com skorpi...@gmail.com wrote: Hi all, I have a data structure in a list as in: [0 0 0 3 0 5 0 0 0 0 1 0 4 0 5 0 0 7 0 0 0 0 0 12 0 0 4] I would like to extract three list from this data: 1) runsOfZero: [3 4 5] 2) runsOfNonZero: [3 8 4] 3) SumOfRunsOfNonZero: [8 17 16] Any suggestions would be appreciated Since this sounds like homework, I won't give actual code, but here's a gameplan: 1. Split the list into sublists based on where the runs of zeros stop and start. 2. Categorize the sublists and place them into lists-of-lists based on whether they have nonzero entries. To do the categorization, you'll have to iterate over the original list and track how many previous 0s you've seen consecutively. 3. Use len() on the nonzero lists to get their length; puts the results into a list (runsOfNonZero) 4. Use sum() on the nonzero lists to get their sums, and put the results into another list (SumOfRunsOfNonZero) 5. Use len() on the all-zero lists to get their length and put the results into a list (runsOfZero) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Identify runs in list
On Oct 3, 10:36 pm, Chris Rebert c...@rebertia.com wrote: On Sat, Oct 3, 2009 at 7:21 PM, skorpi...@gmail.com skorpi...@gmail.com wrote: Hi all, I have a data structure in a list as in: [0 0 0 3 0 5 0 0 0 0 1 0 4 0 5 0 0 7 0 0 0 0 0 12 0 0 4] I would like to extract three list from this data: 1) runsOfZero: [3 4 5] 2) runsOfNonZero: [3 8 4] 3) SumOfRunsOfNonZero: [8 17 16] Any suggestions would be appreciated Since this sounds like homework, I won't give actual code, but here's a gameplan: 1. Split the list into sublists based on where the runs of zeros stop and start. 2. Categorize the sublists and place them into lists-of-lists based on whether they have nonzero entries. To do the categorization, you'll have to iterate over the original list and track how many previous 0s you've seen consecutively. 3. Use len() on the nonzero lists to get their length; puts the results into a list (runsOfNonZero) 4. Use sum() on the nonzero lists to get their sums, and put the results into another list (SumOfRunsOfNonZero) 5. Use len() on the all-zero lists to get their length and put the results into a list (runsOfZero) Cheers, Chris --http://blog.rebertia.com Thanks Chris, Not homework but self learning. Also, forgot to mention that I only count runs greater than 3 (zeros). I will now look over your suggestions. Thanks again -- http://mail.python.org/mailman/listinfo/python-list
Re: Identify runs in list
On Sat, Oct 3, 2009 at 7:53 PM, skorpi...@gmail.com skorpi...@gmail.com wrote: On Oct 3, 10:36 pm, Chris Rebert c...@rebertia.com wrote: snip Since this sounds like homework, I won't give actual code, but here's a gameplan: 1. Split the list into sublists based on where the runs of zeros stop and start. 2. Categorize the sublists and place them into lists-of-lists based on whether they have nonzero entries. To do the categorization, you'll have to iterate over the original list and track how many previous 0s you've seen consecutively. Erm, s/categorization/splitting and move this sentence into point #1, obviously. Mea culpa. :) Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python: Rag October issue available
On Oct 3, 4:29 pm, Bernie edi...@pythonrag.org wrote: Hi, no -its just put on the website. Unless there's a method you can suggest? Not to butt in, but off the top of my head, you could probably set up a mailing list and post the link to the file every cycle - simple but effective. -- http://mail.python.org/mailman/listinfo/python-list
creating class objects inside methods
All, I've got a strange one.. I'm trying to create a class object inside another class object by using the code template below (note.. this isn't the exact code.. I'm having difficulty reproducing it without posting the whole thing) Anyways, the upshot is that the first time the Myclass() constructor is called, the __init__ function gets executed.. The second time, it calls the '__call__' method (and dies, because I don't have a call method defined). To get around this, I've made __call__ a synonym of __init__, which is a horrid hack, and doesn't help me much (since I don't have a good idea what's going on). So - anyone have an idea of what's going on here? It looks like the second time, the Myclass() call is interpreted as a class instance, not a class object, but that seems odd to me.. Is this a python bug? I'm seeing it in 2.6..If necessary, I can post the whole piece of code.. Ed class Myclass: def __init__(self, b='default1', c='default2'): self.b = b; self.c = c; def function(self): other = Myclass(); return(other) a = Myclass(); b = a.function() -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On Oct 3, 11:54 pm, n00m n...@narod.ru wrote: I need your help to understand howhttp://www.spoj.pl/problems/INOUTEST/ can be passed in Python. My code for this is: === import psyco psyco.full() import sys def noo(b): b = b.split() return str(int(b[0]) * int(b[1])) + '\n' def foo(): ##sys.stdin = open('D:/1583.txt', 'rt') a = sys.stdin.readlines() a = a[1:int(a[0]) + 1] a = map(noo, a) sys.stdout.writelines(a) foo() === But it gets Time Limit Exceeded verdict. Any ideas? map() is really at its most efficient when used with built-ins, not user defined functions. In those cases, I believe you're better off using a for-loop or list comprehension. Also: are you sure they support psyco? It's not part of stdlib... I thought something simpler might work: import sys sys.stdin.readline() for line in sys.stdin.readlines(): nums = map(int, line.split()) print nums[0] * nums[1] But although this processes 5.5MB 2 secs on my PC (which meets the 2.5MB/sec criteria outlined in INTEST), I'm getting the same result that you are. Do you know how big the input data set actually is? -- http://mail.python.org/mailman/listinfo/python-list
Re: creating class objects inside methods
On Sat, Oct 3, 2009 at 11:32 PM, horos11 horo...@gmail.com wrote: All, I've got a strange one.. I'm trying to create a class object inside another class object by using the code template below (note.. this isn't the exact code.. I'm having difficulty reproducing it without posting the whole thing) Anyways, the upshot is that the first time the Myclass() constructor is called, the __init__ function gets executed.. The second time, it calls the '__call__' method (and dies, because I don't have a call method defined). To get around this, I've made __call__ a synonym of __init__, which is a horrid hack, and doesn't help me much (since I don't have a good idea what's going on). So - anyone have an idea of what's going on here? It looks like the second time, the Myclass() call is interpreted as a class instance, not a class object, but that seems odd to me.. Is this a python bug? I'm seeing it in 2.6..If necessary, I can post the whole piece of code.. Ed class Myclass: def __init__(self, b='default1', c='default2'): self.b = b; self.c = c; def function(self): other = Myclass(); return(other) a = Myclass(); b = a.function() -- http://mail.python.org/mailman/listinfo/python-list class Myclass: def __init__(self, b='default1', c='default2'): self.b = b self.c = c def function(self): other = Myclass() return other a = Myclass() b = a.function() a __main__.Myclass instance at 0x95cd3ec b __main__.Myclass instance at 0x95cd5ac What's the problem? (Also, you can leave out the ';' at the end of statements. And 'return' isn't a function, you can leave out the ()'s. -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
Do you know how big the input data set actually is? Of course, I don't know exact size of input. It's several MBs, I guess. And mind the fact: their testing machines are PIII (750MHz). -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary with Lists
Shaun wrote: Hi, I'm trying to create a dictionary with lists as the value for each key. I was looking for the most elegant way of doing it... Try using a tuple, instead of a list, for each key. Tuples are immutable, so there's no issue about a key changing while being used in a dictionary. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On Oct 4, 1:58 pm, n00m n...@narod.ru wrote: Do you know how big the input data set actually is? Of course, I don't know exact size of input. It's several MBs, I guess. And mind the fact: their testing machines are PIII (750MHz). Well, then, that's moved the problem from challenging to ludicrous. Being asked to conform to one constraint with no knowledge of the others seems kind of ridiculous. On my machine, the above code handles ~50MB in ~10sec. -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On my machine, the above code handles ~50MB in ~10sec. Means their input 40-50MB 2. I just see: two guys did it in Python and I feel myself curious how on earth?. -- http://mail.python.org/mailman/listinfo/python-list
Re: Identify runs in list
skorpi...@gmail.com skorpi...@gmail.com writes: Any suggestions would be appreciated Look at the docs of the groupby function in the itertools module. -- http://mail.python.org/mailman/listinfo/python-list
Re: creating class objects inside methods
a __main__.Myclass instance at 0x95cd3ec b __main__.Myclass instance at 0x95cd5ac What's the problem? Like I said, the code was a sample of what I was trying to do, not the entire thing.. I just wanted to see if the metaphor was kosher. It sounds to me from your answer that this is unexpected behavior, so I'll go ahead and post the whole thing. My guess is that it is a python bug.. Run it (a simple puzzle game solved by breadth first search), and the first time state() is called inside the method, it calls __init__. Second time, and therafter, it calls __call__. I've highlighted where the code fails by putting a pdb.set_trace(). Anyways, I've got a workaround (simply pass in any new objects needed from the caller), but it is truly annoying that python is either misleading or broken in this way. Attached find code, does not work vs. 2.6.. Ed from collections import deque import copy import pdb class state: def default_board(): return [ [ 1, 'x', 'x', 0 ], [ 2, 2, 3, 4 ], [ 5, 6, 6, 7 ], [ 5, 6, 6, 7 ], [ 8, 9, 10, 10 ], [ 0, 'x', 'x', 0 ] ] def default_types(): return { 1 : [ 0, 0 ], 2 : [ 0, 0, 0, 1 ], 3 : [ 0, 0 ], 4 : [ 0, 0 ], 5 : [ 0, 0, 1, 0 ], 6 : [ 0, 0, 1, 0, 0, 1, 1, 1 ], 7 : [ 0, 0, 1, 0 ], 8 : [ 0, 0 ], 9 : [ 0, 0 ], 10 : [ 0, 0, 0, 1 ] } def default_moves(): return [] def print_move(self, moveno, move): print str(moveno) + : + str(move) + \n def __init__(self, _board=default_board(), _moves=default_moves(), _types=default_types()): self.board = _board self.moves = _moves self.types = _types def possible_moves(self): moves_so_far = set() moves_so_far.add('x') moves_so_far.add(0) ret = [] for y_idx in range(0, len(self.board)): for x_idx in range(0, len(self.board[y_idx])): piece = self.board[y_idx][x_idx] if not piece in moves_so_far: moves = self.legal_moves(y_idx, x_idx) moves_so_far.add(piece) if moves: ret.extend(moves) return ret def is_answer(self): if self.board[5][3] == 1: return True else: return False def legal_moves(self, ycoord, xcoord): ret = [] for dir in [ [ 0, 1 ], [ 0, -1 ], [ 1, 0 ], [ -1, 0 ] ]: ret.extend(self.addmove(dir[0], dir[1], ycoord, xcoord)) return ret def empty(self, type, ycoord, xcoord, pieceno): for itr in range(0, len(type), 2): yy = type[itr] xx = type[itr+1] if not (len(self.board) (yy+ycoord) = 0) or not (len (self.board[yy+ycoord]) xx+xcoord = 0): return False if not self.board[yy+ycoord][xx+xcoord] in [ 0, pieceno ]: return False return True def addmove(self, ymult, xmult, ycoord, xcoord): ret = [] pieceno = self.board[ycoord][xcoord] type= self.types[pieceno] if xmult != 0: for xx in range(xcoord + xmult, -1 if xmult 0 else 4, -1 if xmult 0 else 1): # if xx == 0: # continue if self.empty(type, ycoord, xx, pieceno): ret.append(self.newmove(ycoord, xcoord, ycoord, xx )) else: break if ymult != 0: for yy in range(ycoord + ymult, -1 if ymult 0 else 6, -1 if ymult 0 else 1): # if yy == 0: # continue if self.empty(type, yy, xcoord, pieceno): ret.append(self.newmove(ycoord, xcoord, yy, xcoord)) else: break return ret def newmove(self, fromy, fromx, toy, tox): move = { 'fromx' : fromx, 'fromy' : fromy, 'toy' : toy, 'tox' : tox, 'piece' : self.board[fromy][fromx] } return move def printout_path(self): # print self pdb.set_trace() answer = state() moveno = 0 print \n==\n for moveno in range(0, len(self.moves)): move = self.moves[moveno] self.print_move(moveno, move) answer.apply_move(move) answer.print_board() print \n==\n def print_board(self): for xx in self.board: print : .join([ %2s % str(ii) for ii in xx ]) def to_string(self): return str(self.board) def apply_move(self, move):
Re: Enormous Input and Output Test
And *without* Psyco the above code gets TLE verdict... A kind of mystery :( -- http://mail.python.org/mailman/listinfo/python-list
Re: creating class objects inside methods
Anyways, I see what's going on here: With the line, for state in curstate.next_states(): if not state.to_string() in seen_states: dq.append(state) Inadvertently using the name of a module as a variable seems to be causing this. In any case, this shouldn't cause issues with constructors, so I'd call this a bug.. Ed -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On Oct 3, 11:58 pm, n00m n...@narod.ru wrote: Do you know how big the input data set actually is? Of course, I don't know exact size of input. It's several MBs, I guess. And mind the fact: their testing machines are PIII (750MHz). You know the maximum size of the input, if you can trust the problem definition. The maximum number of lines in the input is 10**6 + 1. The first line is at most 7 characters, plus EOL. The subsequent lines are at most 13 characters each, plus EOL. John -- http://mail.python.org/mailman/listinfo/python-list
[issue7006] The replacement suggested for callable(x) in py3k is not equivalent
Ezio Melotti ezio.melo...@gmail.com added the comment: Benjamin already replaced hasattr(x, __call__) with hasattr(type(x), __call__) in the Python 3.0 What's New in r75090 and r75094, but this still doesn't match completely the behavior of callable(): class Foo(object): pass ... foo = Foo() callable(foo) False hasattr(type(foo), '__call__') True foo() Traceback (most recent call last): File stdin, line 1, in module TypeError: 'Foo' object is not callable There are also other places where hasattr(x, __call__) is still suggested/used (e.g. PEP3100). -- nosy: +benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7006 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7042] test_signal fails on os x 10.6
Jan Hosang jan.hos...@gmail.com added the comment: This is a 64 bit machine and the test failed for the checkout of the python26-maint branch. I just configured and made it without any flags. (Does that produce a 64 bit build?) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7042 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7019] unmarshaling of artificial strings can produce funny longs.
Mark Dickinson dicki...@gmail.com added the comment: 2.6 fix applied in r75203. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7019 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7045] utf-8 encoding error
Martin v. Löwis mar...@v.loewis.de added the comment: I can't reproduce that; it prints fine for me. Notice that it is perfectly fine for Python to represent this as two code points in UCS-2 mode (so that len(s)==2); this is called UTF-16. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7045 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7042] test_signal fails on os x 10.6
Ned Deily n...@acm.org added the comment: By default, 10.6 prefers to run 64-bit architectures when available. You can easily tell whether a python 2.x is running as 32-bit or 64-bit by checking sys.maxint: $ /usr/local/bin/python2.6 -c 'import sys; print sys.maxint' 2147483647 $ /usr/bin/python2.6 -c 'import sys; print sys.maxint' 9223372036854775807 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7042 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7033] C/API - Document exceptions
Georg Brandl ge...@python.org added the comment: Sounds like a useful new API. Two comments: * The version without *base* is not needed. Passing an explicit NULL for *base* is easy enough. * The name PyErr_Create is needlessly different from PyErr_NewException. Something like PyErr_NewExceptionWithDoc is better. -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7042] test_signal fails on os x 10.6
Jan Hosang jan.hos...@gmail.com added the comment: $ ./python.exe -c 'import sys; print sys.maxint' 9223372036854775807 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7042 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7045] utf-8 encoding error
Ezio Melotti ezio.melo...@gmail.com added the comment: I can't reproduce it either on Ubuntu 9.04 32-bit. I tried both from the terminal and from the file, using Py3.2a0. As Martin said, the fact that in narrow builds of Python the codepoints outside the BMP are represented with two surrogate pairs is a known issue. This is how UTF-16 works, even if it has some problematic side-effects. In your example 'line[0]' is not equal to 'first' because line[0] is the codepoint of the first surrogate and 'first' is a scalar value that represents the SHAVIAN LETTER TOT (U+010451). Regarding the traceback you pasted in the first post, have you used print('ё') or print(line[0])? This is what I get using line[0]: line = 'ёѧѕёѦљ' first = 'ё' print(line[0]) Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'utf-8' codec can't encode character '\ud801' in position 0: surrogates not allowed In this case you are getting an error because lone surrogates are invalid and they can't be encoded. If you use line[:2] instead it works because it takes both the surrogates: print(line[0:2]) ё first == line[0:2] True If you really got that error with print('ћ'), then #3297 could be related. Can you also try this and see what it prints? import sys sys.maxunicode -- nosy: +ezio.melotti priority: - normal ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7045 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7028] Add int.hex for symmetry with float.hex
Mark Dickinson dicki...@gmail.com added the comment: Rejecting the request to add int.hex. I've added a note to the hex() docs pointing to float.hex(), in revisions r75025 through r75028. It doesn't really seem worth adding pointers from float.hex and float.fromhex back to integer analogues: it's the float methods that are hard to find, not the int methods. -- resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7028 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7006] The replacement suggested for callable(x) in py3k is not equivalent
Trundle andy-pyt...@hammerhartes.de added the comment: As every type is an instance of `type`, every type also has a `__call__` attribute which means ``hasattr(type(x), '__call__')`` is always true. `callable()` checks whether `tp_call` is set on the type, which cannot be done in Python directly. -- nosy: +Trundle ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7006 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7045] utf-8 encoding error
Arc Riley arcri...@gmail.com added the comment: Python 3.1.1 (r311:74480, Sep 13 2009, 22:19:17) [GCC 4.4.1] on linux2 Type help, copyright, credits or license for more information. import sys sys.maxunicode 1114111 u = 'ё' print(u) Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'utf-8' codec can't encode character '\ud801' in position 0: surrogates not allowed -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7045 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7046] decimal.py: use DivisionImpossible and DivisionUndefined
New submission from Stefan Krah stefan-use...@bytereef.org: In many cases, decimal.py sets InvalidOperation instead of DivisionImpossible or DivisionUndefined. Mark, could I persuade you to isolate these cases by running a modified deccheck2.py from mpdecimal (See attachment), which does not suppress differences in the division functions? -- files: div-deccheck2.py messages: 93490 nosy: mark.dickinson, skrah severity: normal status: open title: decimal.py: use DivisionImpossible and DivisionUndefined Added file: http://bugs.python.org/file15029/div-deccheck2.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7046 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7047] decimal.py: NaN payload conversion
New submission from Stefan Krah stefan-use...@bytereef.org: decimal.py sets InvalidOperation if the payload of a NaN is too large: c = getcontext() c.prec = 4 c.create_decimal(NaN12345) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.7/decimal.py, line 3797, in create_decimal diagnostic info too long in NaN) File /usr/lib/python2.7/decimal.py, line 3733, in _raise_error raise error(explanation) decimal.InvalidOperation: diagnostic info too long in NaN decNumber (and fastdec) set ConversionSyntax. -- messages: 93491 nosy: skrah severity: normal status: open title: decimal.py: NaN payload conversion ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7047 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7047] decimal.py: NaN payload conversion
Changes by Stefan Krah stefan-use...@bytereef.org: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7047 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7048] decimal.py: logb: round the result if it is greater than prec
New submission from Stefan Krah stefan-use...@bytereef.org: from decimal import * c = getcontext() c.prec = 2 c.logb(Decimal(1E123456)) Decimal('123456') This result agrees with the result of decNumber, but the spec says: All results are exact unless an integer result does not fit in the available precision. My interpretation is that the result should be 1.2E+5. -- messages: 93492 nosy: mark.dickinson, skrah severity: normal status: open title: decimal.py: logb: round the result if it is greater than prec ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7048 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7049] decimal.py: NaN result in pow(x, y, z) with prec 1
New submission from Stefan Krah stefan-use...@bytereef.org: If precision 1 is aupported, the following results should not be NaN: Python 2.7a0 (trunk:74738, Sep 10 2009, 11:50:08) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. from decimal import * setcontext(Context(prec=1, rounding=ROUND_UP, Emin=-99, Emax=99, capitals=1, flags=[], traps=[])) pow(Decimal(0), Decimal(3), Decimal(70)) Decimal('NaN') pow(Decimal(3), Decimal(0), Decimal(70)) Decimal('NaN') -- messages: 93493 nosy: skrah severity: normal status: open title: decimal.py: NaN result in pow(x, y, z) with prec 1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7049 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7049] decimal.py: NaN result in pow(x, y, z) with prec 1
Changes by Stefan Krah stefan-use...@bytereef.org: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7049 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2821] unittest.py sys.exit error
Mark Fitzgerald mark.fitzgera...@sympatico.ca added the comment: Agreed that this is clearly not a bug. One way to get the desired behavior from IDLE is to move up to Python 2.7a0+ or Python 3.1.1+, where the 'exit' parameter of unittest.main(), which when set to False, disables the sys.exit() call. Alternatively, in 2.5, just create your own TextTestRunner, as described in the 2.5.2 docs: suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions) unittest.TextTestRunner(verbosity=2).run(suite) -- nosy: +mfitz ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2821 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7050] (x,y) += (1,2) crashes IDLE
New submission from Mark Fitzgerald mark.fitzgera...@sympatico.ca: Start up IDLE. Type (x,y) += (1,2) (without the double-quotes), then press Enter. IDLE unexpectedly terminates without message, pop-up, or warning. Admittedly, this line of code is likely not legal, but shouldn't it just raise SyntaxError? -- components: IDLE messages: 93495 nosy: mfitz severity: normal status: open title: (x,y) += (1,2) crashes IDLE type: crash versions: Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7050 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7050] Augmented assignment of tuple crashes IDLE
Changes by Mark Fitzgerald mark.fitzgera...@sympatico.ca: -- title: (x,y) += (1,2) crashes IDLE - Augmented assignment of tuple crashes IDLE ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7050 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7046] decimal.py: use DivisionImpossible and DivisionUndefined
Mark Dickinson dicki...@gmail.com added the comment: Just to be clear, the decimal context doesn't (and shouldn't) know about DivisionImpossible: there's no DivisionImpossible signal or trap described in the specification, but just a DivisionImpossible heading in the 'exceptional conditions' section of the spec. And that DivisionImpossible condition signals InvalidOperation (according to the spec). (And similarly for DivisionUndefined.) So I don't think decimal.py is in violation of the specification here. But decimal.py could be changed so that a call to _raise_error(context, DivisionImpossible, ...) results in the DivisionImpossible exception being raised instead of the InvalidOperation exception. This shouldn't break anything, since DivisionImpossible is a subclass of InvalidOperation. Note that the appropriate sections of decimal.py do already raise the right conditions (unless some have been missed): e.g., in Decimal._divide, we have the lines: # Here the quotient is too large to be representable ans = context._raise_error(DivisionImpossible, 'quotient too large in //, % or divmod') But the Context._raise_error method currently translates all the exceptional conditions to their corresponding signals, hence raises InvalidOperation in this case. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7046 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7047] decimal.py: NaN payload conversion
Mark Dickinson dicki...@gmail.com added the comment: This is essentially the same issue as issue 7046: the relevant lines in decimal.py read: if d._isnan() and len(d._int) self.prec - self._clamp: return self._raise_error(ConversionSyntax, diagnostic info too long in NaN) and again, the Context._raise_error method translates the ConversionSyntax exceptional condition to the corresponding InvalidOperation signal. Closing as a duplicate, just so we can keep everything one place. -- resolution: - duplicate status: open - closed superseder: - decimal.py: use DivisionImpossible and DivisionUndefined ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7047 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7046] decimal.py: use DivisionImpossible and DivisionUndefined
Mark Dickinson dicki...@gmail.com added the comment: Closed issue 7047 as a duplicate of this one: _raise_error(ConversionSyntax) also raises (if trapped) the InvalidOperation exception, when it could reasonably raise ConversionSyntax instead. It's the same cause as above: _raise_error translates each exceptional condition to the corresponding signal. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7046 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7046] decimal.py: use DivisionImpossible and DivisionUndefined
Changes by Mark Dickinson dicki...@gmail.com: -- assignee: - mark.dickinson priority: - normal stage: - needs patch type: - behavior versions: +Python 2.6, Python 2.7, Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7046 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7049] decimal.py: NaN result in pow(x, y, z) with prec 1
Mark Dickinson dicki...@gmail.com added the comment: This behaviour was deliberate: since the standard doesn't cover three- argument pow, I more-or-less made up my own rules here. :) In this case, I (somewhat arbitrarily) decided that to ensure that any possible pow(a, b, m) result could be represented, m should be strictly less than 10**current_precision. In general, you'd expect to make lots of pow(a, b, m) calls with the same m and differing a and b; it seems less error-prone to have them all these calls fail/pass together than have those with small results pass, and those with larger results fail. Not that I expect there's a single person on this planet who's using three-argument pow with the Decimal type. :) Looking back at this, I'm not quite sure why I chose 'strictly less than' rather than 'less than or equal to'. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7049 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7048] decimal.py: logb: round the result if it is greater than prec
Mark Dickinson dicki...@gmail.com added the comment: Hmm. The problem here is that the specification says nothing at all about what should happen if the integer result does *not* fit in the available precision, so in this case we went with the decNumber behaviour. Rather than rounding, I'd say that a more useful result in this case would be to signal InvalidOperation, on the basis that an inexact result from logb is likely to invalidate most uses of it. Maybe we should ask Mike Cowlishaw what the intended behaviour here is? IEEE 754-2008 (section 5.3.3) requires that languages define a 'logBFormat' type that's always big enough to hold the logB result. If the result is a Decimal, one way to ensure this would be to place constraints on the allowable values emax and emin for a given precision. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7048 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5911] built-in compile() should take encoding option.
Naoki INADA songofaca...@gmail.com added the comment: add sample implementation. -- keywords: +patch Added file: http://bugs.python.org/file15030/compile_with_encoding.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5911 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7049] decimal.py: NaN result in pow(x, y, z) with prec 1
Mark Dickinson dicki...@gmail.com added the comment: Unless anyone else disagrees, I'm going to call this a 'won't fix': I'm happy with the current behaviour. I would like to relax the condition on the modulus from 'modulus 10**prec' to 'modulus = 10**prec', though, so I'm leaving the issue open for that. -- assignee: - mark.dickinson components: +Library (Lib) priority: - low stage: - needs patch type: - behavior versions: +Python 2.7, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7049 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com