ANN: Python Tools for Visual Studio 1.1 Beta 1
We're pleased to announce the release of Python Tools for Visual Studio 1.1 Beta ( http://pytools.codeplex.com/releases/view/76089 ). Python Tools for Visual Studio (PTVS) is an open-source plug-in for Visual Studio which supports programming with the Python programming language. This release includes new core IDE features, a couple of new sample libraries for interacting with Kinect and Excel, and many bug fixes for issues reported since the release of 1.0. Since the last alpha release we've fixed over 30 bugs and implemented several features around the project system and references. For IronPython users you can now add references to .NET projects or .NET assemblies and we'll automatically reload and re-analyze the references when they're rebuilt. For CPython users you can now add a reference to a .pyd extension module and we'll analyze the extension module and provide completions. We've also improved intellisense across multiple Python projects in the same solution. Finally we've added support for using IPython mode w/o PyLab - this enables out-of-line graphs and improves the startup time of the interactive window. We've also added many new features which improve the basic editing experience which were also available during 1.1 Alpha. This includes a feature for automatically adding imports after typing an identifier, a command for cleaning up unused imports, support for recognizing isinstance() calls and using them for providing improved completions, and using goto definition to go to members defined in the standard library. We've also made improvements to the project system so it'll behave more like the C# including proper support of linked files outside of the project directory. And we've made some improvements to our IPython REPL support including support for inline graphs and proper support for IPython's numbered prompts. Finally we've made several small improvements to the debugger including the option to step into the Python standard library while debugging, the option to not break on SystemExit exception with exit codes of zero as well as displaying the Python thread name in the threads window. Altogether this release includes over 130 features and bug fixes since 1.0 - a complete list of the changes is available here: http://bit.ly/IpyTools11Beta1Fixes Another major addition to 1.1 includes the addition of two additional sample libraries available as separate downloads: PyKinect for working with the Kinect Beta SDK and Pyvot for working with Excel spreadsheets. Once downloaded and installed these plug-in to Visual Studio and provide templates; and they provide built-in support for installing into one of the recognized Python interpreters via Tools-Python Tools-Samples. The PyKinect sample is a wrapper around the Kinect SDK and enables development with the Kinect SDK directly from Python. The library presents an API which is similar to the API exposed via the Kinect SDK for C# developers. The sample includes a new template for quickly getting started creating games using PyGame with PyKinect. PyKinect is licensed under a license similar to the existing Kinect SDK. Pyvot (pronounced Pivot) connects familiar data-exploration and visualization tools in Excel with the powerful data analysis and transformation capabilities of Python, with an emphasis on tabular data. It provides a simple and Pythonic interface to Excel, smoothing over the pain points in using the existing Excel object model as exposed via COM. We'd like to thank all of the users who took the time to report issues and feedback for this release: 445363200, Andrew, AphexSA, benpmorgan, chadbr, dgkbny, drgn, holmboe, hyh, jimpeak, juanalumni, lblanchon, liuzhenhai, mahpour, MichaelBaker, po6856, pztrick44, salerio, slide_o_mix, somini, SoonStudios, stakemura, sumitbasu, swift_dev, synergetic, teebot, timeisaparallax, tonyandrewmeyer, xavier_grundus, and Zooba. Thanks, The Python Tools for Visual Studio Team -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Cornice 0.4 released
Hey, We've released Cornice 0.4. Cornice provides helpers to build document REST-ish Web Services with Pyramid This version has multiple new features like a request validation system and a nice errors handling system. The later let your web services return a JSON on all 400s with a structured list of info on errors. The main benefits are: - automatic handling of some HTTP errors. (Ask yourself: is your app handlind 405 or 406 errors?) - automatic web service documentation via Sphinx - simple way to validate and convert requests data, and return structured 400 responses. Check it out : - Documentation : http://packages.python.org/cornice/ - Latest blog post : http://ametaireau.github.com/notmyidea/introducing-cornice.html - Latest release : http://pypi.python.org/pypi/cornice/ - Repository : https://github.com/mozilla-services/cornice We'd love feedback or new contributors ! Cheers Tarek -- Tarek Ziadé | http://ziade.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Insert trusted timestamp to PDF
hello, On Wed, Dec 07, 2011 at 11:39:20PM -0800, marco.ru...@gmail.com wrote: Hi, take a look at this online tool: http://easytimestamping.com I need to create the PDF on my server - it could be any online service, but it must to have any kind of API. It is able to apply RFC3161 compliant trusted timestamps, issued by accredited Certification Authorities. that's no problem in Python... :) http://pypi.python.org/pypi/rfc3161/ The timestamp is applied to the pdf in detached mode (i.e. as a separate .tsr file) I'm afraid that's not good for us - we need to propagate PDF files in enbedded mode. If you need to integrate the timestamping process in a python app, be patient, we will release an API and a command line version very soon. sounds good - what do you think, when will you release that about? Thanks: a. -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On Wed, Dec 7, 2011 at 11:18 PM, 8 Dihedral dihedral88...@googlemail.com wrote: I use the @ decorator to behave exactly like a c macro that does have fewer side effects. I am wondering is there other interesting methods to do the jobs in Python? * Class decorators (http://www.python.org/dev/peps/pep-3129/ ); i.e. using decorators on a class instead of a function/method * Metaclasses (http://docs.python.org/dev/reference/datamodel.html#customizing-class-creation ); a rather more complicated feature capable of serious black magic * Descriptors (http://docs.python.org/dev/reference/datamodel.html#implementing-descriptors ); probably the most rarely directly used of the three Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic variable creation from string
Terry Reedy writes: On 12/7/2011 7:03 PM, Steven D'Aprano wrote: On Wed, 07 Dec 2011 09:09:16 -0800, Massi wrote: Is there a way to create three variables dynamically inside Sum in order to re write the function like this? I should have mentioned in my earlier response that 'variable' is a bit vague and misleading. Python has names bound to objects. The language reference at python.org uses both terms - name and variable - freely. Here is one instance. http://docs.python.org/py3k/reference/executionmodel.html#naming-and-binding # If a name is bound in a block, it is a local variable of that block, # unless declared as nonlocal. If a name is bound at the module level, # it is a global variable. (The variables of the module code block are # local and global.) If a variable is used in a code block but not # defined there, it is a free variable. Perhaps you could consider accepting this. Or trying to change it. Or starting to tell newcomers that the official documentation of the language is, say, vague and misleading. (It seems good to me.) -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
Am 08.12.2011 08:18 schrieb 8 Dihedral: I use the @ decorator to behave exactly like a c macro that does have fewer side effects. I am wondering is there other interesting methods to do the jobs in Python? In combination with a generator, you can do many funny things. For example, you can build up a string: def mkstring(f): Turns a string generator into a string, joining with , . return , .join(f()) def create_answer(): @mkstring def people(): yield Anna yield John yield Theo return The following people were here: + people Many other things are thinkable... Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: order independent hash?
Tim Chase python.l...@tim.thechases.com writes: From an interface perspective, I suppose it would work. However one of the main computer-science reasons for addressing by a hash is to get O(1) access to items (modulo pessimal hash structures/algorithms which can approach O(N) if everything hashes to the same value/bucket), rather than the O(logN) time you'd get from a tree. So folks reaching for a hash/map might be surprised if performance degraded with the size of the contents. In a language like Python, the difference between O(1) and O(log n) is not the primary reason why programmers use dict; they use it because it's built-in, efficient compared to alternatives, and convenient to use. If Python dict had been originally implemented as a tree, I'm sure it would be just as popular. Omitting the factor of O(log n) as functionally equivalent to O(1) is applicable to many situations and is sometimes called soft-O notation. One example from practice is the pre-2011 C++, where the standardization committee failed to standardize hash tables on time for the 1998 standard. Although this was widely recognized as an oversight, a large number of programs simply used tree-based std::maps and never noticed a practical difference between between average-constant-time and logarithmic complexity lookups. -- http://mail.python.org/mailman/listinfo/python-list
how to test attribute existence of feedparser objects
Hi, While using the feedparser library for downloading RSS feeds some of the blog entries seem to have no title. File build\bdist.win32\egg\feedparser.py, line 382, in __getattr__ AttributeError: object has no attribute 'title' Is there a way to test the existence of an attribute? I can use an exception but like below to see whether it exists but this is a clumsy way since the function has to return the title. d=feedparser.parse(url,handlers = [proxy]) try: print TITLE ,d.feed.title except: print HAS NO TITLE wc={} Regards HansPeter -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On Thu, Dec 8, 2011 at 7:59 PM, Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de wrote: Many other things are thinkable... And many more are unthinkable. Can we start an International Obfuscated Python Code Contest? It's the only place such... abhorrences can properly flourish. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
mrjob v0.3.0 released
What is mrjob? --- mrjob is a Python package that helps you write and run Hadoop Streaming jobs. mrjob fully supports Amazon's Elastic MapReduce (EMR) service, which allows you to buy time on a Hadoop cluster on an hourly basis. It also works with your own Hadoop cluster. Some important features: * Run jobs on EMR, your own Hadoop cluster, or locally (for testing). * Write multi-step jobs (one map-reduce step feeds into the next) * Duplicate your production environment inside Hadoop * Upload your source tree and put it in your job's $PYTHONPATH * Run make and other setup scripts * Set environment variables (e.g. $TZ) * Easily install python packages from tarballs (EMR only) * Setup handled transparently by mrjob.conf config file * Automatically interpret error logs from EMR * SSH tunnel to hadoop job tracker on EMR * Minimal setup * To run on EMR, set $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY * To run on your Hadoop cluster, install simplejson and make sure $HADOOP_HOME is set. More info: * Install mrjob: pip install mrjob -OR- easy_install mrjob * Documentation: http://packages.python.org/mrjob/ * PyPI: http://pypi.python.org/pypi/mrjob * Mailing list: http://groups.google.com/group/mrjob * Development is hosted at github: http://github.com/Yelp/mrjob What's new? mrjob v0.3.0 is a major new release. Full details are at http://packages.python.org/mrjob/whats-new.html - here are a few highlights: v0.3.0, 2011-12-07 * Combiners * *_init() and *_final() for mappers, reducers, and combiners * Custom option parsers * Job flow pooling on EMR (saves time and money!) * SSH log fetching * New EMR diagnostic tools A big thanks to the contributors to this release: Steve Johnson, Dave Marin, Wahbeh Qardaji, Derek Wilson, Jordan Andersen, and Benjamin Goldenberg! -- http://mail.python.org/mailman/listinfo/python-list
Re: how to test attribute existence of feedparser objects
On Thu, Dec 8, 2011 at 1:34 AM, HansPeter hanspeter.sl...@gmail.com wrote: Hi, While using the feedparser library for downloading RSS feeds some of the blog entries seem to have no title. File build\bdist.win32\egg\feedparser.py, line 382, in __getattr__ AttributeError: object has no attribute 'title' Is there a way to test the existence of an attribute? I can use an exception but like below to see whether it exists but this is a clumsy way since the function has to return the title. hasattr(obj, attr_name) See docs.python.org/dev/library/functions.html#hasattr That said, sounds like it won't make much difference in the particular case you mention. Also, never use a bare except: clause, unless you know what you're doing and have a really good reason. Do except AttributeError in this case. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Insert trusted timestamp to PDF
On Thursday, December 8, 2011 8:59:31 AM UTC+1, Hegedüs, Ervin wrote: The timestamp is applied to the pdf in detached mode (i.e. as a separate .tsr file) I'm afraid that's not good for us - we need to propagate PDF files in enbedded mode. I'll do some research and let you know if it is feasible. Anyway, it should be possible to embed it later. If you need to integrate the timestamping process in a python app, be patient, we will release an API and a command line version very soon. sounds good - what do you think, when will you release that about? The API is basically ready. We are only missing the authentication method. In less then a couple weeks it should be complete. If you want, I can give you access to a beta version of the API, so you can start integrating the service with your application and then add the required authentication process. Can I contact you privately by email? Thanks for your interest, Marco. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
On 12/08/2011 04:10 AM, Rick Johnson wrote: ... Why has GvR not admonished the atrocious behavior of some people in this community? Why has GvR not admitted publicly the hideous state of IDLE and Tkinter? Where is the rally call? Where is the community spirit? The future of Pythin is in your hands Mr. Van Rossum. Will you step up and do what needs to be done? Will you have the courage? i sincerely hope so. If not, please step down and allow someone to lead. I await the supreme commanders ascent to power. This last part seems like the lord of the rings, but I guess (even if still hope not) that he's serious :D Supposing even that Guido resigns, why do you think that the power should go to you? Power is not something that you can claim for, you have to earn the right, and ranting doesn't normally buy anything ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
On Thu, Dec 8, 2011 at 10:10 PM, Andrea Crotti andrea.crott...@gmail.com wrote: Supposing even that Guido resigns, why do you think that the power should go to you? Power is not something that you can claim for, you have to earn the right, and ranting doesn't normally buy anything ;) Power is something you create. Did you know that you, too, can be head of an open source project the size of Python? It's easy. Just start one! Go to GitHub, Google Code, BitBucket, SourceForge (they all seem to have exactly two capital letters in them - must be important), or any other such site, and start coding your new and most awesome language. You can even make yourself a mailing list so that you can get your revenge on the Evil Python Mafia (hereunder and hereafter the EPM) by ignoring every patch ever submitted! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On 2011-12-08 08:59:26 +, Thomas Rachel said: Am 08.12.2011 08:18 schrieb 8 Dihedral: I use the @ decorator to behave exactly like a c macro that does have fewer side effects. I am wondering is there other interesting methods to do the jobs in Python? In combination with a generator, you can do many funny things. For example, you can build up a string: def mkstring(f): Turns a string generator into a string, joining with , . return , .join(f()) def create_answer(): @mkstring def people(): yield Anna yield John yield Theo return The following people were here: + people Many other things are thinkable... Thomas I am still perplexed about decorators though, am happily using Python for many years without them, but maybe i am missing something? For example in the above case, if I want the names attached to each other with a comma, why wouldn't I just create a function doing exactly this? Why would I first write a single name generator and then decorate it so that I never can get single names anymore (this is the case, isn't it? Once decorated, I can not get the original behaviour of the function anymore. So, above, why not def mkstring(mylist): with the same function declaration and then just call it with a list of names that I generate elsewhere in my program? I just can't identify the use-case for decorators, but as I said, maybe I am missing something. Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
Guido is too busy secretly pouring his cruelty and malice into a master ring to answer trolls. Help yourself to a lesser ring on your way out. On Dec 8, 2011 10:14 PM, Andrea Crotti andrea.crott...@gmail.com wrote: On 12/08/2011 04:10 AM, Rick Johnson wrote: ... Why has GvR not admonished the atrocious behavior of some people in this community? Why has GvR not admitted publicly the hideous state of IDLE and Tkinter? Where is the rally call? Where is the community spirit? The future of Pythin is in your hands Mr. Van Rossum. Will you step up and do what needs to be done? Will you have the courage? i sincerely hope so. If not, please step down and allow someone to lead. I await the supreme commanders ascent to power. This last part seems like the lord of the rings, but I guess (even if still hope not) that he's serious :D Supposing even that Guido resigns, why do you think that the power should go to you? Power is not something that you can claim for, you have to earn the right, and ranting doesn't normally buy anything ;) -- http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
sending a variable to an imported module
Hi list, I'm trying to pass a variable to an imported module without singletons. I've seen in the doc, and tested that I can't use global to do it : === module.py === def testf(): print test === main.py === global test test = 1 imported_module = __import__(module, globals(), locals(), [], -1) importmodule.testf() === output === NameError: global name 'test' is not defined While I was reading many (many) threads about singleton I read people claiming that singletons can always be avoided (I can't remeber the most relevant thread on stackoverflow). I don't want to start a new debate about singletons, I think Internet has enough debates yet. But in my case I'd like to access this variable anywhere and at anytime without having to pass it as a parameter everywhere (this variable is a configuration manager object). How can I achieve that without singletons ? I'm beginner in Python, that's why I'm maybe missing something obvious. Thanks, Bastien Semene -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On Thu, Dec 8, 2011 at 10:22 PM, K.-Michael Aye kmichael@gmail.com wrote: I am still perplexed about decorators though, am happily using Python for many years without them, but maybe i am missing something? For example in the above case, if I want the names attached to each other with a comma, why wouldn't I just create a function doing exactly this? Why would I first write a single name generator and then decorate it so that I never can get single names anymore (this is the case, isn't it? Once decorated, I can not get the original behaviour of the function anymore. The example given is a toy. It's hardly useful. However, there are a number of handy uses for decorators; mostly, they consist of giving a single simple keyword to a complicated set of logic. One example is the @classmethod and @staticmethod decorators - the code to implement them could be uglier than nested inline assembly, but you don't have to care, because you just type @staticmethod in front of your def statement and it does its magic. Here's a handy trick that I'm sure someone has done in a more sophisticated way: def trace(func): if debugmode: return lambda *a,**ka: (print(+func.__name__),func(*a,**ka),print(+func.__name__))[1] return func Then you put @trace in front of all your functions, and if debugmode is False, nothing will be done - but set it to true, and you get console output at the entry and exit of each function. @trace def test(x): print(Test! +x) return 5 test(asdf) test Test! asdf test 5 Again, it's helpful because it condenses all the logic (including the 'debugmode' flag) down to a single high level directive: Trace this function. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: sending a variable to an imported module
On 8 December 2011 11:28, Bastien Semene bsem...@cyanide-studio.com wrote: Hi list, I'm trying to pass a variable to an imported module without singletons. I've seen in the doc, and tested that I can't use global to do it : === module.py === def testf(): print test === main.py === global test test = 1 imported_module = __import__(module, globals(), locals(), [], -1) importmodule.testf() === output === NameError: global name 'test' is not defined While I was reading many (many) threads about singleton I read people claiming that singletons can always be avoided (I can't remeber the most relevant thread on stackoverflow). I don't want to start a new debate about singletons, I think Internet has enough debates yet. But in my case I'd like to access this variable anywhere and at anytime without having to pass it as a parameter everywhere (this variable is a configuration manager object). How can I achieve that without singletons ? I'm beginner in Python, that's why I'm maybe missing something obvious. Put it in its own module and import that module in the places where it is needed. E.g. in your example: == settings.py == test = 1 == module.py == import settings def testf(): print settings.testf == main.py == import module module.testf() In every module that you need 'test', import settings and you will be able to access test. This is why singletons are often not needed in Python (just like most other design patterns). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: sending a variable to an imported module
On 12/08/2011 06:28 AM, Bastien Semene wrote: Hi list, I'm trying to pass a variable to an imported module without singletons. I've seen in the doc, and tested that I can't use global to do it : === module.py === def testf(): print test === main.py === global test test = 1 imported_module = __import__(module, globals(), locals(), [], -1) importmodule.testf() === output === NameError: global name 'test' is not defined Please paste your code and your stacktrace, don't retype them. In the above, you spelled 'imported_module two different ways, and forgot the quotes around modue, so it couldn't run. There are probably other problems, but what's the point? While I was reading many (many) threads about singleton I read people claiming that singletons can always be avoided (I can't remeber the most relevant thread on stackoverflow). I don't want to start a new debate about singletons, I think Internet has enough debates yet. But in my case I'd like to access this variable anywhere and at anytime without having to pass it as a parameter everywhere (this variable is a configuration manager object). How can I achieve that without singletons ? I'm beginner in Python, that's why I'm maybe missing something obvious. global variables are global only within their own module, but you probably knew that. And using the global keyword in main.py isn't accomplishing anything. Since you're not inside a def or a class, test is already global, as soon as you give it a value. You don't pass values to a module, you load the module. And if the module doesn't have any top-level code, you can monkey-patch it to your heart's content, on lines following. If mymodule.py doesn't have a global value test, and you wish it did, you can simply do something like: import mymodule mymodule.test = 42 This attribute of mymodule is totally unrelated to one of the same name in main.py. if you want to refer to it, or to change it again, from main.py, you'd have to use mymodule.test. If the module had top-level code that needed to see your new global, then you'd have a problem, because you can't put it there till after the import returns. Now, most of the time when this sort of thing happens, what you really want is to define another module whose only purpose is to supply these common values. That module should get imported by both your script and your module. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: sending a variable to an imported module
Thanks both, Putting the variable inside a module works well. As the content is an object created inside another module I'm using this trick : module.CONFIG = module.load() So the variable is handled by the module that creates/use it, easy to use and pretty native to understand. Le 08/12/2011 13:15, Dave Angel a écrit : On 12/08/2011 06:28 AM, Bastien Semene wrote: Hi list, I'm trying to pass a variable to an imported module without singletons. I've seen in the doc, and tested that I can't use global to do it : === module.py === def testf(): print test === main.py === global test test = 1 imported_module = __import__(module, globals(), locals(), [], -1) importmodule.testf() === output === NameError: global name 'test' is not defined Please paste your code and your stacktrace, don't retype them. In the above, you spelled 'imported_module two different ways, and forgot the quotes around modue, so it couldn't run. There are probably other problems, but what's the point? While I was reading many (many) threads about singleton I read people claiming that singletons can always be avoided (I can't remeber the most relevant thread on stackoverflow). I don't want to start a new debate about singletons, I think Internet has enough debates yet. But in my case I'd like to access this variable anywhere and at anytime without having to pass it as a parameter everywhere (this variable is a configuration manager object). How can I achieve that without singletons ? I'm beginner in Python, that's why I'm maybe missing something obvious. global variables are global only within their own module, but you probably knew that. And using the global keyword in main.py isn't accomplishing anything. Since you're not inside a def or a class, test is already global, as soon as you give it a value. You don't pass values to a module, you load the module. And if the module doesn't have any top-level code, you can monkey-patch it to your heart's content, on lines following. If mymodule.py doesn't have a global value test, and you wish it did, you can simply do something like: import mymodule mymodule.test = 42 This attribute of mymodule is totally unrelated to one of the same name in main.py. if you want to refer to it, or to change it again, from main.py, you'd have to use mymodule.test. If the module had top-level code that needed to see your new global, then you'd have a problem, because you can't put it there till after the import returns. Now, most of the time when this sort of thing happens, what you really want is to define another module whose only purpose is to supply these common values. That module should get imported by both your script and your module. -- http://mail.python.org/mailman/listinfo/python-list
Documentation using Sphinx
Hi, I am trying source code documentation using Sphinx. Here i have to copy paste all modules in to *.rst file, that is painful. Have any way to create documentation (doc for all modules, classes and methods in the project directory) from project folder quickly. I also plannig to add a code browsing facility in the document, for example: code should display if we click on a method/class name in the doc, does sphinx has this feature??? or what tool i have to choose for that ???. -- http://mail.python.org/mailman/listinfo/python-list
Misleading error message of the day
I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File stdin, line 1, in module ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to too {many, few} values to unpack (are you sure you wanted to unpack a string?) if the RHS is a basestring? -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/08/2011 02:23 PM, Roy Smith wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File stdin, line 1, inmodule ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to too {many, few} values to unpack (are you sure you wanted to unpack a string?) if the RHS is a basestring? I had a few errors sometimes because I thought I passed in a list while I passed only a string, which since it's still iterable would just work but explode later. A nicer message wouldn't have really actually helped though, not sure it's worth to make an exception for such a thing.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 1:23 AM, Roy Smith r...@panix.com wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File stdin, line 1, in module ValueError: too many values to unpack Definitely weird! I smell a job for a linter though. If you had just happened to have a two-character string there, it would have quietly succeeded, and left you wondering what was going on - imho rather worse. This isn't something for the language to solve; the same issue would come up if you had something like: a=[1,2,3] b=[4,5,6] c,d=a # oops, mucked up the a,b side Or any other iterable. Looks to me like a chance for an informational note from your lint facility, not a change to the language. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/8/11 2:23 PM, Roy Smith wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File stdin, line 1, inmodule ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to too {many, few} values to unpack (are you sure you wanted to unpack a string?) if the RHS is a basestring? Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) -- 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: Misleading error message of the day
Roy Smith wrote: I just spent a while beating my head against this one. # Python 2.6 a, b = 'foo' Traceback (most recent call last): File stdin, line 1, in module ValueError: too many values to unpack The real problem is that there's too *few* values to unpack! It should have been a, b = 'foo', 'bar' I understand why it's generating the exception it does (the string is an iterable), but man, did that message throw off my thought processes and lead me down some totally bogus debugging paths. It's an unusual case to want to unpack a string. Maybe the message should changed to too {many, few} values to unpack (are you sure you wanted to unpack a string?) if the RHS is a basestring? string are iterable, considering this, the error is correct. Values to unpack in 'foo' are 'f', 'o', 'o' a,b,c = 'foo' print a,b,c f o o JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation using Sphinx
On 12/08/2011 02:09 PM, sajuptpm wrote: Hi, I am trying source code documentation using Sphinx. Here i have to copy paste all modules in to *.rst file, that is painful. Have any way to create documentation (doc for all modules, classes and methods in the project directory) from project folder quickly. I also plannig to add a code browsing facility in the document, for example: code should display if we click on a method/class name in the doc, does sphinx has this feature??? or what tool i have to choose for that ???. You should never copy and paste anything ;) Have a look at the autodoc plugin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Am 08.12.2011 15:47, schrieb Robert Kern: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) Not possible in the general case (as the right-hand side might be an arbitrary iterable/iterator...). -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thursday, December 8, 2011 9:47:02 AM UTC-5, Robert Kern wrote: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) I don't know if that would have done the trick for me on this particular one. On the other hand, adding expected X, got Y to the message would generally be a good thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong but most people would probably agree that it's not the most useful message that could have been produced. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thursday, December 8, 2011 10:16:56 AM UTC-5, Heiko Wundram wrote: Am 08.12.2011 15:47, schrieb Robert Kern: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) Not possible in the general case (as the right-hand side might be an arbitrary iterable/iterator...). Why not? Take this example: def i(): i = 0 while True: print returning:, i yield i i += 1 a, b = i() ./iter.py returning: 0 returning: 1 returning: 2 Traceback (most recent call last): File ./iter.py, line 10, in module a, b = i() ValueError: too many values to unpack The exception was raised when i() returned it's third value, so saying expected 2, got 3 is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Am 08.12.2011 16:42, schrieb Roy Smith: The exception was raised when i() returned it's third value, so saying expected 2, got 3 is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. Please explain how that error message (in case you're not aiming at the actual count of elements in the source) differs from the curent wording too many values, as you're simply displaying expected n, got n+1 where n is visible from the immediate exception output... -- --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/08/2011 03:42 PM, Roy Smith wrote: Why not? Take this example: def i(): i = 0 while True: print returning:, i yield i i += 1 a, b = i() ./iter.py returning: 0 returning: 1 returning: 2 Traceback (most recent call last): File ./iter.py, line 10, inmodule a, b = i() ValueError: too many values to unpack The exception was raised when i() returned it's third value, so saying expected 2, got 3 is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown. Yes but how do you know how many values you generated when it quits? I mean I don't know how it work internally, but it should keep a temporary list of the yielded values to be able to find out how many values are there.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 2:55 AM, Andrea Crotti andrea.crott...@gmail.com wrote: Yes but how do you know how many values you generated when it quits? I mean I don't know how it work internally, but it should keep a temporary list of the yielded values to be able to find out how many values are there.. Iterator unpacking works roughly thus: 1) Count up how many results you need (call that N) 2) N times, get a value from the iterator. If StopIteration is raised, swallow it and raise ValueError because there were too few values. 3) Attempt to get one more value from the iterator. If StopIteration is NOT raised, raise ValueError because there were too many values. At no point is the total size of the iterator counted (it could, after all, be infinite). When ValueError is raised, all that's known is that StopIteration wasn't raised at the end of the process. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some IPC pointers
On 12/01/2011 08:03 AM, Andrew Berg wrote: I've done some research, but I'm not sure what's most appropriate for my situation. What I want to do is have a long running process that spawns processes (that aren't necessarily written in Python) and communicates with them. The children can be spawned at any time and communicate at any time. Being able to communicate with non-local processes would be nice, but is not necessary. The implementation needs to be cross-platform, but child processes will use the same OS as the parent during runtime. I don't think I'll ever need to transfer anything complicated or large - just strings or possibly tuples/lists. I'd rather not go outside the standard library (but I'd consider it). I don't need to worry about compatibility with older Python versions; if it only works with Python 3.2, that's not a problem. I'm thinking sockets, but perhaps there's something simpler/easier. Considering your requirements, I'd suggest a RESTful web service. It is fairly trivial to write HTTP clients in most languages, and python's standard library comes with a simple HTTP server so writing the server is easy as well. In context, the long running process will be the server, the children processes will be the client. Writing HTTP client is fairly trivial in most languages, the protocol is platform independent, and it is fairly trivial to communicate with non-local processes over the LAN or the Internet. As a plus, it's well standardized. As the data interchange format, I suggest either xml or json. There is a library for xml and json in almost any popular languages. Python comes with both. -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On 2011-12-08 11:43:12 +, Chris Angelico said: On Thu, Dec 8, 2011 at 10:22 PM, K.-Michael Aye kmichael@gmail.com wrote: I am still perplexed about decorators though, am happily using Python for many years without them, but maybe i am missing something? For example in the above case, if I want the names attached to each other with a comma, why wouldn't I just create a function doing exactly this? Why would I first write a single name generator and then decorate it so that I never can get single names anymore (this is the case, isn't it? Once decorated, I can not get the original behaviour of the function anymore. The example given is a toy. It's hardly useful. However, there are a number of handy uses for decorators; mostly, they consist of giving a single simple keyword to a complicated set of logic. One example is the @classmethod and @staticmethod decorators - the code to implement them could be uglier than nested inline assembly, but you don't have to care, because you just type @staticmethod in front of your def statement and it does its magic. Here's a handy trick that I'm sure someone has done in a more sophisticated way: def trace(func): if debugmode: return lambda *a,**ka: (print(+func.__name__),func(*a,**ka),print(+func.__name__))[1] return func Then you put @trace in front of all your functions, and if debugmode is False, nothing will be done - but set it to true, and you get console output at the entry and exit of each function. @trace def test(x): print(Test! +x) return 5 test(asdf) test Test! asdf test 5 Again, it's helpful because it condenses all the logic (including the 'debugmode' flag) down to a single high level directive: Trace this function. ChrisA I understand this one, it seems really useful. And maybe i start to sense some more applicability. Like this, with extra flags that could be set at run time, I could influence the way a function is executed without designing the function too complex, but by decorating it, which at the end could be easier to read than complicated if-then statements in the function. Thanks for your example. Michael -- http://mail.python.org/mailman/listinfo/python-list
adding elements to set
I've wasted way too much time for this, which is surely not a Python bug, not something that surprised me a lot. I stupidly gave for granted that adding an object to a set would first check if there are equal elements inside, and then add it. As shown below this is not clearly the case.. Is it possible to get that behaviour implementing another magic method in my C class or I just have use another function to check (as I'm doing now). class C(object): def __init__(self, x): self.x = x def __eq__(self, other): return self.x == other.x if __name__ == '__main__': s = set() c1 = C(1) c2 = C(1) assert c1 == c2 s.add(c1) s.add(c2) print len(s) -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On Fri, Dec 9, 2011 at 3:24 AM, K.-Michael Aye kmichael@gmail.com wrote: I understand this one, it seems really useful. And maybe i start to sense some more applicability. Like this, with extra flags that could be set at run time, I could influence the way a function is executed without designing the function too complex, but by decorating it, which at the end could be easier to read than complicated if-then statements in the function. Right, and less duplication usually results in less bugs, too. Obviously if you go to any greater level of complexity than this you'd want to break the lambda out into a proper function, and possibly play with an indent level (increment on call, decrement on return). You can also easily add the run-time check, and anything else you want to do, too. It'll still all be buried away in the definition of trace(), and on functions that you want to trace, you need still only have @trace and nothing else. One piece of sophistication that I would rather like to see, but don't know how to do. Instead of *args,**kwargs, is it possible to somehow copy in the function's actual signature? I was testing this out in IDLE, and the fly help for the function no longer gave useful info about its argument list. This is why I say that this has almost certainly been done before in a much better way. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
On Fri, Dec 9, 2011 at 3:34 AM, Andrea Crotti andrea.crott...@gmail.com wrote: I've wasted way too much time for this, which is surely not a Python bug, not something that surprised me a lot. I stupidly gave for granted that adding an object to a set would first check if there are equal elements inside, and then add it. It checks for equality using hashes. By default, in Python 2, objects' hashes are their ids - meaning that no two of them hash alike, and you'll get duplicates in your set. (In Python 3, the default appears to be that they're unhashable and hence can't go into the set at all.) class C(object): def __init__(self, x): self.x = x def __eq__(self, other): return self.x == other.x def __hash__(self): return hash(self.x) This chains the hashing requirement to the child, just as it chains the equality check. You can then stuff your objects into a set with more expected results. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
Andrea Crotti wrote: I've wasted way too much time for this, which is surely not a Python bug, not something that surprised me a lot. I stupidly gave for granted that adding an object to a set would first check if there are equal elements inside, and then add it. As shown below this is not clearly the case.. Is it possible to get that behaviour implementing another magic method in my C class or I just have use another function to check (as I'm doing now). class C(object): def __init__(self, x): self.x = x def __eq__(self, other): return self.x == other.x if __name__ == '__main__': s = set() c1 = C(1) c2 = C(1) assert c1 == c2 s.add(c1) s.add(c2) print len(s) Python's sets are hash-based; you have to implement a __hash__() method for the elements that ensures that c1 == c2 implies hash(c1) == hash(c2). class C(object): ... def __init__(self, x): self.x = x ... def __eq__(self, other): return self.x == other.x ... def __hash__(self): return hash(self.x) ... c1 = C(1) c2 = C(1) c1 == c2 True s = set() s.add(c1) s.add(c2) len(s) 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On 12/8/2011 10:38 AM, Chris Angelico wrote: One piece of sophistication that I would rather like to see, but don't know how to do. Instead of *args,**kwargs, is it possible to somehow copy in the function's actual signature? I remember seeing this in a PEP that is planned to be implemented in 3.3. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0 -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
Decorators are great for adding common functionality to several functions without duplicating code. For example, I have one for my IRC bot that checks that the person sending the command is authorized to use the command. It's only if mask in owner list then execute function else say access denied, but it simplifies the code and the intent of each function that uses it becomes more obvious. I have another that puts functions in a common try/except clause, which again simplifies the functions and makes them easier to understand. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0 -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
Chris Angelico wrote: It checks for equality using hashes. By default, in Python 2, objects' hashes are their ids - meaning that no two of them hash alike, and you'll get duplicates in your set. (In Python 3, the default appears to be that they're unhashable and hence can't go into the set at all.) $ python3.2 -c'print({object(), object()})' {object object at 0x269dd00, object object at 0x269db60} The only thing that has changed (in 2.7) is the algorithm to calculate the hash value. The bits are rotated to turn the four least significant bits into the most signicant ones. According to a comment in Objects/objects.c the change leads to fewer hash collisions. $ python2.6 -c'o = object(); print hash(o) == id(o)' True $ python2.7 -c'o = object(); print hash(o) == id(o)' False $ python2.7 -c'o = object(); print hash(o) == id(o)4 | (id(o)0xF)60' True $ python3.2 -c'o = object(); print(hash(o) == id(o)4 | (id(o)0xF)60)' True -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
On Fri, Dec 9, 2011 at 4:32 AM, Peter Otten __pete...@web.de wrote: The only thing that has changed (in 2.7) is the algorithm to calculate the hash value. The bits are rotated to turn the four least significant bits into the most signicant ones. According to a comment in Objects/objects.c the change leads to fewer hash collisions. Interesting, but what I saw was this: class C(object): def __init__(self, x): self.x = x def __eq__(self, other): return self.x == other.x s=set() c1=C(1) s.add(c1) Traceback (most recent call last): File pyshell#163, line 1, in module s.add(c1) TypeError: unhashable type: 'C' (This is in IDLE from Python 3.2 on Windows.) However, s.add(object()) works fine. So subclasses don't get that. Odd. Makes sense though - you can't get this unexpected behaviour as easily. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
One piece of sophistication that I would rather like to see, but don't know how to do. Instead of *args,**kwargs, is it possible to somehow copy in the function's actual signature? I was testing this out in IDLE, and the fly help for the function no longer gave useful info about its argument list. You can use the decorator module in PyPI to do this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/08/11 09:30, Roy Smith wrote: On Thursday, December 8, 2011 9:47:02 AM UTC-5, Robert Kern wrote: Would including the respective numbers help your thought processes? ValueError: too many values to unpack (expected 2, got 3) I don't know if that would have done the trick for me on this particular one. On the other hand, adding expected X, got Y to the message would generally be a good thing. given the nature of the message, and the interaction with iterators-of-arbitrary/infinite length, it might have to be reduced to Expected N, got more or for the case where you didn't get enough, you know how many you got: Expected N, but only got M. But the extra information would certainly be useful in tracking it down. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
On 08/12/2011 04:10, Rick Johnson wrote: [snip] I believe this community has a cancer. A cancer that is rotting us from the inside. A cancer that has metastasis and is spreading like wild fire. pedanticThe problem with a cancer is not that it rots, but that it grows uncontrollably./pedantic *Inquisitive Joe asked:* What is the source of this cancer Rick? The source is a direct result of insufficient leadership. Our current leader has failed us. Maybe he never wanted to be a leader, but when you go and declare yourself a benevolent dictator for life you'd damn well better act like one! He never declared himself benevolent dictator for life, others declared him so. Why has GvR not admonished the atrocious behavior of some people in this community? Why has GvR not admitted publicly the hideous state of IDLE and Tkinter? Where is the rally call? Where is the community spirit? The future of Pythin is in your hands Mr. Van Rossum. Will you step up and do what needs to be done? Will you have the courage? i sincerely hope so. If not, please step down and allow someone to lead. I await the supreme commanders ascent to power. GvR isn't our leader, we are his followers. There's a difference. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 2011-12-08, Roy Smith r...@panix.com wrote: On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong My favorite is still the old classic error from and old Unix printer port driver: lp0 on fire but most people would probably agree that it's not the most useful message that could have been produced. -- Grant Edwards grant.b.edwardsYow! Don't hit me!! I'm in at the Twilight Zone!!! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
(some, very, long, list, of, variable, names, to, get, the, stuff, unpacked, into) = function_that_should_return_a_14_tuple() raises ValueError: too many values to unpack Quick, what's the bug? Did I forget a variable on the LHS, or is my function returning more things than it should? I know it's supposed to be 14, but I don't know which side is wrong. Had it said ... expected 13, got 14, I would know immediately. Error messages should be as explicit as possible. It's just like bug reports. The basic mantra of a bug report is: 1) This is what I did 2) This is what I expected to happen 3) This is what I observed happen 4) This is how what I observed differed from what I expected Saying, expected X, got Y is more explicit than got too many -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
Chris Angelico wrote: On Fri, Dec 9, 2011 at 4:32 AM, Peter Otten __pete...@web.de wrote: The only thing that has changed (in 2.7) is the algorithm to calculate the hash value. The bits are rotated to turn the four least significant bits into the most signicant ones. According to a comment in Objects/objects.c the change leads to fewer hash collisions. Interesting, but what I saw was this: class C(object): def __init__(self, x): self.x = x def __eq__(self, other): return self.x == other.x s=set() c1=C(1) s.add(c1) Traceback (most recent call last): File pyshell#163, line 1, in module s.add(c1) TypeError: unhashable type: 'C' (This is in IDLE from Python 3.2 on Windows.) However, s.add(object()) works fine. So subclasses don't get that. Odd. Makes sense though - you can't get this unexpected behaviour as easily. It seems to be even subtler: you can subclass if you don't implement __eq__(): class C(object): pass ... {C()} {__main__.C object at 0x17defd0} -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
Chris Angelico ros...@gmail.com wrote: On Fri, Dec 9, 2011 at 4:32 AM, Peter Otten __pete...@web.de wrote: The only thing that has changed (in 2.7) is the algorithm to calculate the hash value. The bits are rotated to turn the four least significant bits into the most signicant ones. According to a comment in Objects/objects.c the change leads to fewer hash collisions. Interesting, but what I saw was this: class C(object): def __init__(self, x): self.x = x def __eq__(self, other): return self.x == other.x s=set() c1=C(1) s.add(c1) Traceback (most recent call last): File pyshell#163, line 1, in module s.add(c1) TypeError: unhashable type: 'C' (This is in IDLE from Python 3.2 on Windows.) However, s.add(object()) works fine. So subclasses don't get that. Odd. Makes sense though - you can't get this unexpected behaviour as easily. Yes, the documentation describes this although I don't think anything highlights that it is a change from Python 2.x: [http://docs.python.org/py3k/reference/datamodel.html] If a class does not define an __eq__() method it should not define a __hash__() operation either; if it defines __eq__() but not __hash__(), its instances will not be usable as items in hashable collections. If a class defines mutable objects and implements an __eq__() method, it should not implement __hash__(), since the implementation of hashable collections requires that a keys hash value is immutable (if the objects hash value changes, it will be in the wrong hash bucket). So in Python 2.x you could define __eq__ and get the default __hash__ which would break dictionaries. With Python 3.x defining __eq__ will disable the default __hash__ although if you subclass a class that has both methods you could still get in a mess by redefining one without the other. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, Dec 8, 2011 at 1:42 PM, Roy Smith r...@panix.com wrote: (some, very, long, list, of, variable, names, to, get, the, stuff, unpacked, into) = function_that_should_return_a_14_tuple() raises ValueError: too many values to unpack Quick, what's the bug? Did I forget a variable on the LHS, or is my function returning more things than it should? I know it's supposed to be 14, but I don't know which side is wrong. Had it said ... expected 13, got 14, I would know immediately. If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get expected n args, got n+1 even if the iterable would return 24 items instead of 14, or would never stop returning items. Error messages should be as explicit as possible. It's just like bug reports. The basic mantra of a bug report is: 1) This is what I did 2) This is what I expected to happen 3) This is what I observed happen 4) This is how what I observed differed from what I expected Saying, expected X, got Y is more explicit than got too many -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Benjamin Kaplan wrote: On Thu, Dec 8, 2011 at 1:42 PM, Roy Smith r...@panix.com wrote: (some, very, long, list, of, variable, names, to, get, the, stuff, unpacked, into) = function_that_should_return_a_14_tuple() raises ValueError: too many values to unpack Quick, what's the bug? Did I forget a variable on the LHS, or is my function returning more things than it should? I know it's supposed to be 14, but I don't know which side is wrong. Had it said ... expected 13, got 14, I would know immediately. If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get expected n args, got n+1 even if the iterable would return 24 items instead of 14, or would never stop returning items. Not so. There could be fewer, in which you could see expected 13 args, got 7. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, Dec 8, 2011 at 2:09 PM, Ethan Furman et...@stoneleaf.us wrote: Benjamin Kaplan wrote: On Thu, Dec 8, 2011 at 1:42 PM, Roy Smith r...@panix.com wrote: (some, very, long, list, of, variable, names, to, get, the, stuff, unpacked, into) = function_that_should_return_a_14_tuple() raises ValueError: too many values to unpack Quick, what's the bug? Did I forget a variable on the LHS, or is my function returning more things than it should? I know it's supposed to be 14, but I don't know which side is wrong. Had it said ... expected 13, got 14, I would know immediately. If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get expected n args, got n+1 even if the iterable would return 24 items instead of 14, or would never stop returning items. Not so. There could be fewer, in which you could see expected 13 args, got 7. You mean like this? a,b,c = ['a','b'] Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 2 values to unpack -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Roy Smith wrote: On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong but most people would probably agree that it's not the most useful message that could have been produced. You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. JM -- http://mail.python.org/mailman/listinfo/python-list
Sybase module 0.40pre2 released
WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. Please downolad, test and report any problems with the pre-release. ** This version is a pre-release not intended for production use ** The module is available here: http://downloads.sourceforge.net/python-sybase/python-sybase-0.40pre2.tar.gz The module home page is here: http://python-sybase.sourceforge.net/ MAJOR CHANGES SINCE 0.40pre1: Better support for building against Sybase 15 on Windows, UNIX/Linux and 64-bit platforms. MAJOR CHANGES SINCE 0.39: Modify the DateTimeAsPython output conversion to return None when NULL is output support for Python without threads Ignore additional non-error codes from Sybase (1918 and 11932) Use outputmap in bulkcopy mode (thanks to patch by Cyrille Froehlich) Raise exception when opening a cursor on a closed connection Added unit tests Added new exception DeadLockError when Sybase is in a deadlock situation Add command properties CS_STICKY_BINDS and CS_HAVE_BINDS Added support for inputmap in bulkcopy reuse command and cursor when calling cursor.execute with same request Use ct_setparam to define ct_cursor parameters types instead of ct_param implicit conversion for CS_DATE_TYPE in CS_DATETIME_TYPE DataBuf Adding ct_cmd_props wrapper Increase DataBuf maxlength for params of a request when using CS_CHAR_TYPE params so that the buf can be reused BUGS CORRECTED SINCE 0.39: Corrected money type when using CS_MONEY4 (close bug 2615821) Corrected thread locking in ct_cmd_props (thanks to patch by Cyrille Froehlich) Corrected bug in type mapping in callproc (thanks to report by Skip Montanaro) Correct passing None in a DataBuf (thanks to patch by Bram Kuijvenhoven) The full ChangeLog is here: https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_40pre2/ChangeLog -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/8/11 4:21 PM, Chris Angelico wrote: On Fri, Dec 9, 2011 at 2:55 AM, Andrea Crottiandrea.crott...@gmail.com wrote: Yes but how do you know how many values you generated when it quits? I mean I don't know how it work internally, but it should keep a temporary list of the yielded values to be able to find out how many values are there.. Iterator unpacking works roughly thus: 1) Count up how many results you need (call that N) 2) N times, get a value from the iterator. If StopIteration is raised, swallow it and raise ValueError because there were too few values. 3) Attempt to get one more value from the iterator. If StopIteration is NOT raised, raise ValueError because there were too many values. At no point is the total size of the iterator counted (it could, after all, be infinite). When ValueError is raised, all that's known is that StopIteration wasn't raised at the end of the process. unpack_iterable() has the original object available to it, not just the iterator. It could opportunistically check for __len__() and fall back to the less informative message when it is absent. -- 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
Numpy ndarray to C array
I am trying to pass a multi-dimensional ndarray to C as a multi- dimensional C array for the purposes of passing it to mathematica. They already have a wrapper for a 1-D Python list. where the list is copied to list. Shown below: static PyObject * mathlink_PutIntegerList(mathlink_Link *self, PyObject *args) { PyObject* seq; PyObject* obj; longi, len, result; int*list; len = PyObject_Length(seq); list = PyMem_New(int, len); for(i = 0; i len; i++) { obj = PySequence_GetItem(seq, i); list[i] = PyInt_AsLong(obj); } CheckForThreadsAndRunLink(self,result = MLPutIntegerList(self-lp, list, len)); PyMem_Free(list); CHECKNOTEQUAL(result,MLSUCCESS,self); Py_INCREF(Py_None); return Py_None; } I would like to create a similar wrapper which accepts an ndarray and provides the array laid out in memory like a C array declared explicitly as int a[m][n] I also need to pass the length of the array at each level i as dim[i]. Since this is pretty much the only function I plan to wrap, I'd like to avoid using boost, swig, etc. Any help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Jean-Michel Pichavant wrote: You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. Which thread was that? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Python horks on WinXP path names
I'm running Python 2.7 on WinXP (ActiveState community version) and when I try to do this: if __name__ == '__main__': root = Tkinter.Tk() root.withdraw() fileNames = tkFileDialog.askopenfilenames() root.destroy() print fileNames # windows filename gets for fileName in fileNames: print fileName file = open(fileName, 'r') for line in file.readlines(): print line.strip() I get this: C:\Documents and Settings\eric\Desktop\PythonShoppython picker.py {C:/Documents and Settings/eric/Desktop/PythonShop/cereal.py} { Traceback (most recent call last): File picker.py, line 31, in module file = open(fileName, 'r') IOError: [Errno 2] No such file or directory: u'{' That is, fileName is in a form that open() doesn't recognize. On a BSD box the code works fine. What's going on with the file name and how do I fix it? TIA, eric -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
MRAB pyt...@mrabarnett.plus.com writes: GvR isn't our leader, we are his followers. There's a difference. :-) +1 QotW -- \ “Guaranteed to work throughout its useful life.” —packaging for | `\ clockwork toy, Hong Kong | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
Benjamin Kaplan wrote: On Thu, Dec 8, 2011 at 2:09 PM, Ethan Furman et...@stoneleaf.us wrote: Benjamin Kaplan wrote: If the RHS was a tuple or a list, yes you could know immediately. But unpacking works with any iterable, so it probably doesn't special-case lists and tuples. Iterables don't have a size- they just keep going until StopIteration is raised. So in EVERY SINGLE CASE, you would get expected n args, got n+1 even if the iterable would return 24 items instead of 14, or would never stop returning items. Not so. There could be fewer, in which you could see expected 13 args, got 7. You mean like this? a,b,c = ['a','b'] Traceback (most recent call last): File stdin, line 1, in module ValueError: need more than 2 values to unpack This is still not as helpful as this would be: ValueError: need 3 values, received 2 ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python horks on WinXP path names
On Thu, Dec 8, 2011 at 1:16 PM, Eric einazaki...@yahoo.com wrote: I'm running Python 2.7 on WinXP (ActiveState community version) and when I try to do this: if __name__ == '__main__': root = Tkinter.Tk() root.withdraw() fileNames = tkFileDialog.askopenfilenames() root.destroy() print fileNames # windows filename gets for fileName in fileNames: print fileName file = open(fileName, 'r') for line in file.readlines(): print line.strip() I get this: C:\Documents and Settings\eric\Desktop\PythonShoppython picker.py {C:/Documents and Settings/eric/Desktop/PythonShop/cereal.py} { Traceback (most recent call last): File picker.py, line 31, in module file = open(fileName, 'r') IOError: [Errno 2] No such file or directory: u'{' That is, fileName is in a form that open() doesn't recognize. On a BSD box the code works fine. What's going on with the file name and how do I fix it? http://bugs.python.org/issue5712 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python horks on WinXP path names
On Thu, Dec 8, 2011 at 3:16 PM, Eric einazaki...@yahoo.com wrote: I'm running Python 2.7 on WinXP (ActiveState community version) and when I try to do this: if __name__ == '__main__': root = Tkinter.Tk() root.withdraw() fileNames = tkFileDialog.askopenfilenames() root.destroy() print fileNames # windows filename gets for fileName in fileNames: print fileName file = open(fileName, 'r') for line in file.readlines(): print line.strip() I get this: C:\Documents and Settings\eric\Desktop\PythonShoppython picker.py {C:/Documents and Settings/eric/Desktop/PythonShop/cereal.py} { Traceback (most recent call last): File picker.py, line 31, in module file = open(fileName, 'r') IOError: [Errno 2] No such file or directory: u'{' That is, fileName is in a form that open() doesn't recognize. On a BSD box the code works fine. What's going on with the file name and how do I fix it? Try replacing your current print fileNames line with the follwing: print type(fileNames), repr(fileNames) The behavior you're seeing seems to indicate that fileNames is really a single filename (a single unicode string), rather than a list of file names (a list containing strings). I don't know why that would be, but it would be helpful to confirm that that is, indeed, the problem. I guess you should also double check that the version of the code you're running on windows does, in fact, call tkFileDialog.askopenfilenames() rather than tkFileDialog.askopenfilename() The two calls are just one letter different, but the first one is supposed to return a list, and the second one is supposed to just return a single string. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, 08 Dec 2011 18:10:17 +, Grant Edwards wrote: On 2011-12-08, Roy Smith r...@panix.com wrote: On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong My favorite is still the old classic error from and old Unix printer port driver: lp0 on fire but most people would probably agree that it's not the most useful message that could have been produced. not as useless as Keyboard Error press F1 to continue -- I once witnessed a long-winded, month-long flamewar over the use of mice vs. trackballs...It was very silly. (By Matt Welsh) -- http://mail.python.org/mailman/listinfo/python-list
tracking variable value changes
Hello, Is there a way to create a C-style pointer in (pure) Python so the following code will reflect the changes to the variable a in the dictionary x? For example: a = 1.0 b = 2.0 x = {a:a, b:b} x {'a': 1.0, 'b': 2.0} a = 100.0 x {'a': 1.0, 'b': 2.0} ## at this point, I would like the value ## associated with the a key to be 100.0 ## rather than 1.0 If I make a and b numpy arrays, then changes that I make to the values of a and b show up in the dictionary x. My understanding is that when I redefine the value of a, that Python is creating a brand-new float with the value of 100.0, whereas when I use numpy arrays I am merely assigning a new value to the same object. Is there some way to rewrite the code above so the change of a from 1.0 to 100.0 is reflected in the dictionary. I would like to use simple datatypes such as floats, rather than numpy arrays or classes. I tried using weakref's, but got the error that a weak reference cannot be created to a float. Catherine -- http://mail.python.org/mailman/listinfo/python-list
Re: Python horks on WinXP path names
On Dec 8, 2:43 pm, Ian Kelly ian.g.ke...@gmail.com wrote: On Thu, Dec 8, 2011 at 1:16 PM, Eric einazaki...@yahoo.com wrote: I'm running Python 2.7 on WinXP (ActiveState community version) and when I try to do this: if __name__ == '__main__': root = Tkinter.Tk() root.withdraw() fileNames = tkFileDialog.askopenfilenames() root.destroy() print fileNames # windows filename gets for fileName in fileNames: print fileName file = open(fileName, 'r') for line in file.readlines(): print line.strip() I get this: C:\Documents and Settings\eric\Desktop\PythonShoppython picker.py {C:/Documents and Settings/eric/Desktop/PythonShop/cereal.py} { Traceback (most recent call last): File picker.py, line 31, in module file = open(fileName, 'r') IOError: [Errno 2] No such file or directory: u'{' That is, fileName is in a form that open() doesn't recognize. On a BSD box the code works fine. What's going on with the file name and how do I fix it? http://bugs.python.org/issue5712 Thanks! eric -- http://mail.python.org/mailman/listinfo/python-list
Re: tracking variable value changes
On Thu, Dec 8, 2011 at 3:17 PM, Catherine Moroney catherine.m.moro...@jpl.nasa.gov wrote: Is there some way to rewrite the code above so the change of a from 1.0 to 100.0 is reflected in the dictionary. I would like to use simple datatypes such as floats, rather than numpy arrays or classes. No, there is not. You would need to use a mutable data type, and float is not mutable (neither are ints or strings). -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 7:58 AM, alister alister.w...@ntlworld.com wrote: not as useless as Keyboard Error press F1 to continue If it said press F1 to ignore then I would agree. This, however, is more akin to replace user and strike any key to continue, but more implicit. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Numpy ndarray to C array
On 12/8/11 7:56 PM, Enrico wrote: I am trying to pass a multi-dimensional ndarray to C as a multi- dimensional C array for the purposes of passing it to mathematica. They already have a wrapper for a 1-D Python list. where the list is copied to list. Shown below: I would like to create a similar wrapper which accepts an ndarray and provides the array laid out in memory like a C array declared explicitly as int a[m][n] I also need to pass the length of the array at each level i as dim[i]. Since this is pretty much the only function I plan to wrap, I'd like to avoid using boost, swig, etc. You will find it better to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists In this case, you are looking for the PyArray_AsCArray() function: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_AsCArray -- 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: tp_new, tp_alloc, tp_init
Michael Hennebry wrote: I've been reading about writing extension types in C and am rather fuzzy about the relationship between tp_new, tp_alloc and tp_init. Most especially, why tp_new? It seems to me that tp_alloc and tp_init would be sufficient. tp_new and tp_init correspond to the Python methods __new__ and __init__, and they're separated for the same reasons they are in Python. tp_alloc is separate because it allows a type to use a custom memory allocator without disturbing the rest of the initialisation mechanism. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get a correct entry in the menu for a Python application on Mac OS X
Detlev Offenbach wrote: I am fairly new to Mac OS X and would like to know, what I have to do to make my Python application show the correct name in the menu bar. What did I do so far. I created an application package containing the .plist file with correct entries and a shell script, that starts the correct Python interpreter with the the main script. I don't think that will work, because the executable that your shell script is starting is in an app bundle of its own, and MacOSX will be using the plist from that bundle, which just has the generic Python name in it. There are a couple of things you could do: 1) Use py2app to create your app bundle. It does the right things -- not sure exactly what, but it works. 2) Hack things at run time. I use the following PyObjC code in PyGUI to set the application name: from Foundation import NSBundle ns_bundle = NSBundle.mainBundle() ns_info = ns_bundle.localizedInfoDictionary() if not ns_info: ns_info = ns_bundle.infoDictionary() ns_info['CFBundleName'] = my_application_name -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: tracking variable value changes
On Thu, Dec 8, 2011 at 1:17 PM, Catherine Moroney catherine.m.moro...@jpl.nasa.gov wrote: Hello, Is there a way to create a C-style pointer in (pure) Python so the following code will reflect the changes to the variable a in the dictionary x? For example: a = 1.0 b = 2.0 x = {a:a, b:b} x {'a': 1.0, 'b': 2.0} a = 100.0 x {'a': 1.0, 'b': 2.0} ## at this point, I would like the value ## associated with the a key to be 100.0 ## rather than 1.0 If I make a and b numpy arrays, then changes that I make to the values of a and b show up in the dictionary x. My understanding is that when I redefine the value of a, that Python is creating a brand-new float with the value of 100.0, whereas when I use numpy arrays I am merely assigning a new value to the same object. Sort of. In the code above, you are binding a and x[a] to the same float object. Then when you do a = 100.0, you are rebinding a but not x[a]. In the case of arrays it's the same story, except that you can also *modify* the contents of the array instead of rebinding to a new array. In that case both a and x[a] are still bound to the original array, the contents of which have changed. You can get the same effect with a float by putting it in a container object and binding both variables to the same container objects rather than to the float directly. Then, to change the value, change the contents of the container object. What you use as a container object is up to you. Some use a 1-element list, although I find that ugly. -- http://mail.python.org/mailman/listinfo/python-list
Re: tracking variable value changes
Catherine Moroney catherine.m.moro...@jpl.nasa.gov writes: Is there a way to create a C-style pointer in (pure) Python so the following code will reflect the changes to the variable a in the dictionary x? No, Python doesn't do pointers. Rather, objects have references and that's how the program accesses the objects. For example: a = 1.0 b = 2.0 x = {a:a, b:b} x {'a': 1.0, 'b': 2.0} a = 100.0 x {'a': 1.0, 'b': 2.0} ## at this point, I would like the value ## associated with the a key to be 100.0 ## rather than 1.0 You might like that, but it's just not how Python works. Python doesn't have C-style pointers. Python also doesn't have variables (even though the documentation uses that term; IMO it's a mistake, and leads to confusion similar to this). What Python has are references to objects. One kind of reference is a name; another kind of reference is a value in a dictionary. The assignment operator ‘=’ is the binding operator. It binds the reference on the left side to the object on the right side. If I make a and b numpy arrays, then changes that I make to the values of a and b show up in the dictionary x. Yes, because the objects are mutable; you can change them and existing references are still referring to the same object. They don't “show up in the dictionary”; the dictionary item is just referring to the same object it did before you made the change. My understanding is that when I redefine the value of a Please think of it, instead, as re-binding the name ‘a’ to a new value. that Python is creating a brand-new float with the value of 100.0, Yes (or at least that's the abstraction being presented to you; it may not be implemented exactly that way, but it's sufficient that we Python programmers treat it that way). whereas when I use numpy arrays I am merely assigning a new value to the same object. No, you're modifying the object. A numpy array itself contains references. By altering one of the elements in an array, you are re-binding one of its references to a different number. Is there some way to rewrite the code above so the change of a from 1.0 to 100.0 is reflected in the dictionary. I would like to use simple datatypes such as floats, rather than numpy arrays or classes. Please follow the Python tutorial URL:http://docs.python.org/tutorial/ from beginning to end. Not just read, but do it: work through the exercises to understand what each one is teaching you. That will give you a firm grounding in Python's data model, including mutable and immutable types, references and binding. Do bear in mind what I said above, though, about “variable” being a misleading term, and ignore its implications from the C language. -- \“Good judgement comes from experience. Experience comes from | `\ bad judgement.” —Frederick P. Brooks | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: tracking variable value changes
On 8 December 2011 21:50, Ian Kelly ian.g.ke...@gmail.com wrote: You can get the same effect with a float by putting it in a container object and binding both variables to the same container objects rather than to the float directly. Then, to change the value, change the contents of the container object. What you use as a container object is up to you. Some use a 1-element list, although I find that ugly. This kind of trick is not often necessary anyway. It may be a sign that there is a better approach to the problem that the OP is trying to solve. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen under windows 7
Hello, i have something like this under windows 7: print(try command...) arglist = [PATH_TO_7ZIP,a, -sfx, archive_name, *, -r, -p,PASSWORD] p = subprocess.Popen(args=arglist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=srcdir) output, error = p.communicate() if output: print output print (Eyerthing is good) press_any_key_to_continue() The script works, but there is a little problem. When I double-click the python file, then the command line will open and the script starts. I can read try command... in the command line window under windows 7. But then I have to enter the return key in order that the script will go on. After I had entered the return key the script completed sucessfully and I saw the output. What can I do, to prevent pressing the return key? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
Chris Angelico wrote: One piece of sophistication that I would rather like to see, but don't know how to do. Instead of *args,**kwargs, is it possible to somehow copy in the function's actual signature? I was testing this out in IDLE, and the fly help for the function no longer gave useful info about its argument list. If you want to roll your own, it looks something like this: 2.x code -- def trace(func, debugmode=debugmode): if debugmode: name = func.__name__ argspec = inspect.getargspec(func) signature = inspect.formatargspec( formatvalue=lambda val: , *argspec)[1:-1] # trim parens new_func = ( 'def _wrapper_(%(signature)s):\n' 'print(+func.__name__)\n' 'result = func(%(signature)s)\n' 'print(+func.__name__)\n' 'return result\n' % {'signature':signature} ) evaldict = {'func':func} exec new_func in evaldict wrapped = evaldict['_wrapper_'] wrapped.__name__ = name wrapped.__doc__ = func.__doc__ wrapped.__module__ = func.__module__ wrapped.__dict__ = func.__dict__ wrapped.func_defaults = func.func_defaults return wrapped return func -- The downside (which you get even with Michele's decorator module) is that tracebacks aren't quite as clean. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
Chris Angelico wrote: One piece of sophistication that I would rather like to see, but don't know how to do. Instead of *args,**kwargs, is it possible to somehow copy in the function's actual signature? I was testing this out in IDLE, and the fly help for the function no longer gave useful info about its argument list. And here it is with Michele's decorator module: 2.x code (probably the same in 3.x, but haven't tested) from decorator import decorator debugmode = True def trace(func): if debugmode: @decorator def traced(func, *a, **ka): print(, func.__name__, a, ka) result = func(*a, **ka) print(, func.__name__) return result return traced(func) return func @trace def test(x): a simple test print(Test! +x) return 5 ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
In article jbqui9$33c$1...@reader1.panix.com, Grant Edwards invalid@invalid.invalid wrote: On 2011-12-08, Roy Smith r...@panix.com wrote: On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong My favorite is still the old classic error from and old Unix printer port driver: lp0 on fire Well, if you're going to go there, ed had (and probably still does) have but a single all-purpose error message: ?. The old v6 unix chess program was somewhat more verbose. It said, eh? (unless I'm mixing that up with something else). -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On 12/09/2011 07:13 AM, Ethan Furman wrote: Jean-Michel Pichavant wrote: You have to opportunity to not use unpacking anymore :o) There is a recent thread were the dark side of unpacking was exposed. Unpacking is a cool feautre for very small applications but should be avoided whenever possible otherwise. Which thread was that? perhaps the one that talks about `a, a.foo = 1, 2` blowing up? -- http://mail.python.org/mailman/listinfo/python-list
ANN: Speedometer 2.4 - bandwidth and download monitor
Announcing Speedometer 2.8 -- Speedometer home page: http://excess.org/speedometer/ Download: http://excess.org/speedometer/speedometer-2.8.tar.gz New in this release: - Added a linear scale option: -l. Best used in combination with -m (and possibly -n) to customize the range to be displayed. Thanks to jukie.net for sponsoring this feature. - Replace silly curved reading with a weighted moving average - New option to display all values in bits per second: -s - New options to set minimum (-n) and maximum (-m) values displayed on the graphs in bytes/s. Defaults are -n 32 and -m 2**32 - Accept shortened versions of -rx and -tx: -r and -t My intent is to drop use of the original forms in 3.0 and add --long-versions of all options - Use IEC notation of sizes MiB, GiB etc. - Install script as both speedometer.py and speedometer About Speedometer = Speedometer is a console bandwidth and file download progress monitor with a linear/logarithmic bandwidth display and a simple command-line interface. Speedometer requires Urwid for full-console bar graph display. Urwid may be downloaded from: http://excess.org/urwid/ Speedometer is released under the GNU LGPL. -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Thu, 08 Dec 2011 18:10:17 +, Grant Edwards wrote: On 2011-12-08, Roy Smith r...@panix.com wrote: On Thursday, December 8, 2011 10:03:38 AM UTC-5, Jean-Michel Pichavant wrote: string are iterable, considering this, the error is correct. Yes, I understand that the exception is correct. I'm not saying the exception should be changed, just that we have the opportunity to produce a more useful error message. The exception would be equally correct if it was: ValueError: you did something wrong My favorite is still the old classic error from and old Unix printer port driver: lp0 on fire but most people would probably agree that it's not the most useful message that could have been produced. I forget where I saw this, but somebody took a screen shot of an error message from a GUI application that said something like: A fatal error occurred: no error and then aborted the app. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen under windows 7
On 12/09/2011 09:41 AM, Frank van den Boom wrote: What can I do, to prevent pressing the return key? I didn't have Windows 7 right now, but that shouldn't happen with the code you've given; when trimming code for posting, you should check that the trimmed code still have the exact same problem. -- http://mail.python.org/mailman/listinfo/python-list
Re: adding elements to set
On 12/8/2011 1:54 PM, Duncan Booth wrote: Yes, the documentation describes this although I don't think anything highlights that it is a change from Python 2.x: [http://docs.python.org/py3k/reference/datamodel.html] The Python 3 docs are 're-based' on 3.0, with change notes going forward from that new base. This change should have been in 'What's New in Python 3.0', though I did not find it. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
[OT] Book authoring
Greetings, Any recommendations for a book authoring system that supports the following: 1. Code examples (with syntax highlighting and line numbers) 2. Output HTML, PDF, ePub ... 3. Automatic TOC and index 4. Search (in HTML) - this is a nice to have Can I somehow use Sphinx? Thanks, -- Miki -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
On Fri, Dec 9, 2011 at 1:07 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I forget where I saw this, but somebody took a screen shot of an error message from a GUI application that said something like: A fatal error occurred: no error and then aborted the app. An errant error! Sounds like the stuff that happens here... http://thedailywtf.com/Series/Error_0x27_d.aspx This is getting quite off-topic though. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Misleading error message of the day
In article mailman.3464.1323402417.27778.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: http://thedailywtf.com/Series/Error_0x27_d.aspx This is getting quite off-topic though. Getting off-topic, perhaps, but your comment really does bring some closure. When I was pondering the original, too many values to unpack message, I did indeed utter a few WTFs :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: I love the decorator in Python!!!
On Dec 9, 2:38 am, Chris Angelico ros...@gmail.com wrote: One piece of sophistication that I would rather like to see, but don't know how to do. Instead of *args,**kwargs, is it possible to somehow copy in the function's actual signature? I was testing this out in IDLE, and the fly help for the function no longer gave useful info about its argument list. The 3rd party 'decorator' module takes care of issues like docstrings function signatures. I'd really like to see some of that functionality in the stdlib though. -- http://mail.python.org/mailman/listinfo/python-list
[issue13441] TestEnUSCollation.test_strxfrm() fails on Solaris
Changes by Stefan Krah stefan-use...@bytereef.org: -- nosy: +skrah ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13441 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5689] Support xz compression in tarfile module
Lars Gustäbel l...@gustaebel.de added the comment: For those who want to test it first, I post the current state of the patch here. It is ready for commit, there are no failing tests. If nobody objects, I will apply it this weekend. -- Added file: http://bugs.python.org/file23880/2011-12-08-tarfile-lzma.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5689 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5689] Support xz compression in tarfile module
STINNER Victor victor.stin...@haypocalc.com added the comment: Some comments about 2011-12-08-tarfile-lzma.diff: elif self.buf.startswith(b\x5d\x00\x00\x80) or self.buf.startswith(b... Micro-optimization: you can use self.buf.startswith((b\x5d\x00\x00\x80, b\xfd7zXZ)) here. raise ValueError(mode must be 'r' or 'w'.) Error messages usually don't end with a dot (or am I wrong?). It would be better to use a skip instead of just return here: def test_no_name_argument(self): if self.mode.endswith(bz2) or self.mode.endswith(xz): # BZ2File and LZMAFile have no name attribute. return In _Stream.__init__, for zlib: self.exception = zlib.error Could you add a test for this change? -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5689 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13441] TestEnUSCollation.test_strxfrm() fails on Solaris
STINNER Victor victor.stin...@haypocalc.com added the comment: See also the issue #7442. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13441 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7136] Idle File Menu Option Improvement
maniram maniram maniandra...@gmail.com added the comment: +1 on renaming New Window to New File -- nosy: +maniram.maniram ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7136 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5905] strptime fails in non-UTF locale
STINNER Victor victor.stin...@haypocalc.com added the comment: Oh! I think that I understood the problem: if HAVE_WCSFTIME is not defined, timemodule.c uses strftime(), instead of wcsftime(), encode input format and decode the format. It uses UTF-8 to encode/decode, whereas the right encoding is the locale encoding. Attached patch should fix this issue. @Antoine: Do you have any idea why HAVE_WCSFTIME was not defined? wcsftime() is defined in wchar.h on Ubuntu. In configure, it is tested using AC_CHECK_FUNCS(wcsftime) -- components: +Unicode keywords: +patch resolution: invalid - status: closed - open Added file: http://bugs.python.org/file23881/tzname_encoding.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5905 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1062] nice to have a way to tell if a socket is bound
maniram maniram maniandra...@gmail.com added the comment: perhaps you can subclass socket.socket and make a function wrapper around bind and connect that sets a variable if called like: class sock(socket.socket): def bind(self,*args): self.is_bound = True -- nosy: +maniram.maniram ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1062 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1062] nice to have a way to tell if a socket is bound
maniram maniram maniandra...@gmail.com added the comment: oops should be class sock(socket.socket): _bind = socket.socket.bind def bind(self,*args): self.is_bound = True self._bind(self,*args) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1062 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13555] cPickle MemoryError when loading large file (while pickle works)
New submission from Phillies p...@bethgelab.org: When I try to load a large file (1GB) cPickle crashes with a MemoryError: $python test.py Traceback (most recent call last): File /tmp/test.py, line 8, in module A2 = cPickle.load(f2) MemoryError test.py contains following code: import numpy as np import cPickle A = np.random.randn(196,24) f = open('test.pydat', 'w') cPickle.dump(A,f) f.close() f2 = open('test.pydat', 'rb') A2 = cPickle.load(f2) System: cPickle 1.71 python 2.7.2 Ubuntu 11.10 amd64 Memory is not an issue as a) pickle works nicely and b) my computer has 122GB free RAM -- components: None messages: 149027 nosy: phillies priority: normal severity: normal status: open title: cPickle MemoryError when loading large file (while pickle works) type: crash versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13555 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13555] cPickle MemoryError when loading large file (while pickle works)
maniram maniram maniandra...@gmail.com added the comment: Maybe Ubuntu doesn't think it is safe to allocate the memory. -- nosy: +maniram.maniram ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13555 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13555] cPickle MemoryError when loading large file (while pickle works)
Philipp Lies p...@bethgelab.org added the comment: Well, replace cPickle by pickle and it works. So if there is a memory allocation problem cPickle should be able to handle it, especially since it should be completely compatible to pickle. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13555 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com