Re: SHPAML v0.1 -- HAML-like language for Python
Just to follow up on the announcement below, SHPAML is a mini language that can help you build web pages more quickly. It runs under Python versions 2.4, 2.5, 2.6, and 3.1. Since the original announcement, I have written a tutorial that allows you try out your own SHPAML examples online: http://shpaml.webfactional.com/tutorial/1 I have also fixed some minor bugs, removed some unneeded features, and cleaned up the download process. As this is a new project, feedback is especially welcome. You can follow this link to find the mailing list: http://shpaml.webfactional.com/discuss Cheers, Steve Howell On Dec 11, 5:10 am, Steve Howell showel...@yahoo.com wrote: SHPAML is a HAML-like language for Python. If you are not familiar with HAML, it is a markup language implemented in Ruby that allows you to create web pages with an indentation-based syntax. SHPAML is not an exact port of HAML, but it shares the same big goal of slimming your markup, and it is written in Python! It is a simple, lightweight preprocessor and intended to be used in many authoring schemes, whether you are producing HTML directly or integrating with a templating system. More details can be found here: http://shpaml.webfactional.com/ It is an early version, but it has been well tested in practice already and is feature-complete for its fairly minimal goals as of now. The site has a link to a mailing list (Google Groups) for further discussion, if this interests you! Thanks, Steve Howell -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: getlist question
On Thu, Dec 24, 2009 at 6:32 PM, MRAB pyt...@mrabarnett.plus.com wrote: Victor Subervi wrote: On Thu, Dec 24, 2009 at 3:28 PM, MRAB pyt...@mrabarnett.plus.commailto: pyt...@mrabarnett.plus.com wrote: Victor Subervi wrote: Hi; I have the following code: try: trueVal = form.getlist(storeColNames[i]) colNames.append(storeColNames[i]) if len(trueVal) 1: trueVal = string.join(trueVal, ',') Unless you're using a very old version of Python, you should be using the string method: trueVal = ','.join(trueVal) values.append(trueVal) elif len(trueVal) == 1: print storeColNames[i], trueVal, 'br /' trueVal = '%s' % trueVal[0] values.append(trueVal) if len(trueVal) 0: sql = '%s=%s' % (storeColNames[i], trueVal) sqlUpdate.append(sql) except: raise This works fine except when storeColNames[i] returns no data. Now, if I were dealing with getfirst instead of getlist, I could easily put in a nonsense default data value such as '%$#' and check for that. But how can I do that or something similar (and preferably more elegant) with getlist, which takes only the one name parameter? You just need to check whether len(trueVal) == 0. Simple. The problem is that it doesn't see the value at all trueVal = form.getlist(storeColNames[i]) test = ','.join(trueVal) if len(test) == 0: trueVal == '' It simply doesn't register storeColNames[i] if there is nothing provided from the referring page. Here's a test printout: [snip] You can see from the above part with breaks that Availability isn't logged. But it is in the insert statement...without a value, which throws an error. The complete code follows: [snip] Try working through the code by hand for that value. Well I've done that. What happens is the storeColNames registers the Availability field naturally enough; however, as I stated before, the getlist doesn't fetch anything because there is nothing to fetch! No such value is passed! So, what I need to do is figure out a way to log the fact that no value is fetched. What I have currently, unfortunately, simply ignores the unfetchable value. As I stated before, I need to log the fact that no such value is obtained. Please...how do I do that?? TIA, beno -- http://mail.python.org/mailman/listinfo/python-list
Re: Mechanize - Click a table row to navigate to detail page
Brian D schrieb: A search form returns a list of records embedded in a table. The user has to click on a table row to call a Javascript call that opens up the detail page. It's the detail page, of course, that really contains the useful information. How can I use Mechanize to click a row? You can't, if there is javascript involved. You can try use Firebug to see what the javascript eventually calls, with which parameters. Then construct that url based on the parameters in the table row's javascript (which of course you have to parse yourself out of the code) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Join a thread and get the return value of a function
Il Fri, 25 Dec 2009 05:19:46 +1100, Lie Ryan ha scritto: import threading class MyThread(threading.Thread): def join(self): super(MyThread, self).join() return self.result class Worker(MyThread): def run(self): total = 0 for i in range(random.randrange(1, 10)): total += i self.result = total import random ts = [Worker() for i in range(100)] for t in ts: t.start() for t in ts: print t.join() Thank you. And merry christmas! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extra fields for logging
On Thu, 24 Dec 2009 05:06:48 -0800, Joan Miller wrote: I'm trying to add some extra fields to logging, I'm following this information [1] but it faills in my case. [...] I get = KeyError: 'host' Please post the entire traceback you get. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I install GMPY 1.11 on a Mac with OS X 10.6 and Python 3.1?
On Fri, Dec 25, 2009 at 1:48 AM, Mensanator mensana...@aol.com wrote: On Dec 24, 10:18 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Thu, Dec 24, 2009 at 9:11 PM, Mensanator mensana...@aol.com wrote: Ok, so I got a MacBook Air. Has OS X 10.6 (Snow Leopard) and Python 2.6.1 already installed. So I install Xcode, download macports and download gmpy-1.11rc1. Following the instructions in mac_build.txt, I do the following: - sudo /opt/local/bin/port install gmp This works fine. Then I do - python setup.py install This also works (a few warnings, but nothing looked serious). Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. import gmpy gmpy.version() '1.11' python gmpy_test.py Unit tests for gmpy 1.11 on Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] Testing gmpy 1.11 (GMP 4.3.1), default caching (100, 128) gmpy_test_cvr 151 tests, 0 failures . . . 25 tests in gmpy_test_rnd.__test__.rand 1469 tests in 42 items. 1469 passed and 0 failed. Test passed. Looks like a viable gmpy module for 2.6. What do I do AFTER I install Python 3.1? Just running python3.1 from the same directory doesn't work. I've spent the last 5 days trying to figure that out. I hosed it so bad I somehow wrecked the 2.6 version to the point where it won't even load. I just got done doing a factory restore of the entire OS to undo everything I did. Re-did all the above and got it back working. Haven't re- installed 3.1 yet. Anbody have any idea how to make this work? Did you run setup.py with python3? Python 3.1 won't install itself as the default python install for compatibility reasons so you have to run python3 install setup.py to install it for that version of python. I wondered why there was both python3 and python3.1 in the bin directory. But why, when I type... $ python3 ...do I get... Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. [1]+ Stopped python3 I get the same result with python3.1. So, no, trying python3 is of no help, same errors as before. There's hundreds of them, but they start out $ /Library/Frameworks/Python.framework/Versions/3.1/bin/python3 setup.py install running install running build running build_ext building 'gmpy' extension creating build/temp.macosx-10.3-fat-3.1 creating build/temp.macosx-10.3-fat-3.1/src Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk Please check your Xcode installation gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -I./src -I/ opt/local/include -I/Library/Frameworks/Python.framework/Versions/3.1/ include/python3.1 -c src/gmpy.c -o build/temp.macosx-10.3-fat-3.1/src/ gmpy.o In file included from src/gmpy.c:206: /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:11:20: error: limits.h: No such file or directory /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:14:2: error: #error Something's broken. UCHAR_MAX should be defined in limits.h. /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:18: Any other ideas? Do I have to install a separate Python 3? That's not a Python 3 problem. It appears to be a problem in the build script. Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk My guess would be you're on Snow Leopard while the original developer is either on Tiger or Leopard. The script wants to use the 10.4 SDK but Apple only includes the SDKs for the latest 2 versions of OS X. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Is it possible to get the erroneous variable when getting a NameError exception?
Hi. I'm trying to evaluate a string and getting a NameError (it is expected, since the variable my_number wasn't provided in the locals dictionary). --snip start-- eval(my_number 10, {__builtins__:None}, {}) Traceback (most recent call last): File stdin, line 1, in ? File string, line 0, in ? NameError: name 'my_number' is not defined --snip end-- My question is: how can i know which variable name / symbol causes the NameError exception? In my example, this symbol is my_number. Using that information, I will be able to print a nice error message to the user. Thanks Dotan -- http://mail.python.org/mailman/listinfo/python-list
Re: getlist question
Victor Subervi wrote: Well I've done that. What happens is the storeColNames registers the Availability field naturally enough; however, as I stated before, the getlist doesn't fetch anything because there is nothing to fetch! No such value is passed! Well, what does getlist return when the situation you're describing as getlist doesn't fetch anything occurs? Does is raise an exception? Does it return 0? Does it return None? Does it return an empty list? An empty string? An empty tuple? Does it return False? Does it not return at all and causes the universe to fall into a black hole? So, what I need to do is figure out a way to log the fact that no value is fetched. What I have currently, unfortunately, simply ignores the unfetchable value. As I stated before, I need to log the fact that no such value is obtained. Please...how do I do that?? Please be less vague. What part do you have a problem with? Checking whether no value is fetched or log the fact? -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get the erroneous variable when getting a NameError exception?
On Fri, 25 Dec 2009 17:29:48 +0200, Dotan Barak wrote: Hi. I'm trying to evaluate a string and getting a NameError (it is expected, since the variable my_number wasn't provided in the locals dictionary). --snip start-- eval(my_number 10, {__builtins__:None}, {}) Traceback (most recent call last): File stdin, line 1, in ? File string, line 0, in ? NameError: name 'my_number' is not defined --snip end-- My question is: how can i know which variable name / symbol causes the NameError exception? In my example, this symbol is my_number. Using that information, I will be able to print a nice error message to the user. You mean just like the error message that Python already prints? NameError: name 'my_number' is not defined Don't waste your time re-inventing the wheel. But if you do insist on reinventing the wheel, here are some tools to help you: try: my_number except NameError, e: print str(e) print type(e) print e.args -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get the erroneous variable when getting a NameError exception?
Dotan Barak wrote: Hi. I'm trying to evaluate a string and getting a NameError (it is expected, since the variable my_number wasn't provided in the locals dictionary). --snip start-- eval(my_number 10, {__builtins__:None}, {}) Traceback (most recent call last): File stdin, line 1, in ? File string, line 0, in ? NameError: name 'my_number' is not defined --snip end-- My question is: how can i know which variable name / symbol causes the NameError exception? In my example, this symbol is my_number. Using that information, I will be able to print a nice error message to the user. Thanks Dotan Recover the exception, and examine the tuple of args or the message string. try: ... eval(my_number 10, {__builtins__:None}, {}) ... except NameError,e: ... print e.args ... print e.message ... (name 'my_number' is not defined,) name 'my_number' is not defined -- http://mail.python.org/mailman/listinfo/python-list
Re: getlist question
On Fri, Dec 25, 2009 at 11:35 AM, Carsten Haese carsten.ha...@gmail.comwrote: Victor Subervi wrote: Well I've done that. What happens is the storeColNames registers the Availability field naturally enough; however, as I stated before, the getlist doesn't fetch anything because there is nothing to fetch! No such value is passed! Well, what does getlist return when the situation you're describing as getlist doesn't fetch anything occurs? Does is raise an exception? Does it return 0? Does it return None? Does it return an empty list? An empty string? An empty tuple? Does it return False? Does it not return at all and causes the universe to fall into a black hole? It returns nothing. I believe I've stated that three times now. So, what I need to do is figure out a way to log the fact that no value is fetched. What I have currently, unfortunately, simply ignores the unfetchable value. As I stated before, I need to log the fact that no such value is obtained. Please...how do I do that?? Please be less vague. What part do you have a problem with? Checking whether no value is fetched or log the fact? No value is fetched because there is no value to fetch. I want to be able to log the fact that no value was fetched. How do I do that? Am I not being clear? Here, let me try again, as I began this thread with my first post. I thought it was so easy, so clear. If I use getfirst, I can set a default to log whether getfirst gets anything or not. I cannot do that with getlist. Is there a work-around? TIA, beno -- http://mail.python.org/mailman/listinfo/python-list
Re: getlist question
Victor Subervi wrote: On Fri, Dec 25, 2009 at 11:35 AM, Carsten Haese carsten.ha...@gmail.com mailto:carsten.ha...@gmail.com wrote: Victor Subervi wrote: Well I've done that. What happens is the storeColNames registers the Availability field naturally enough; however, as I stated before, the getlist doesn't fetch anything because there is nothing to fetch! No such value is passed! Well, what does getlist return when the situation you're describing as getlist doesn't fetch anything occurs? Does is raise an exception? Does it return 0? Does it return None? Does it return an empty list? An empty string? An empty tuple? Does it return False? Does it not return at all and causes the universe to fall into a black hole? It returns nothing. I believe I've stated that three times now. Bzzzt! Wrong! Nothing is not a Python object, and stating it three times doesn't make it any less wrong. The result you're getting is a Python object. It might represent Nothingness to you, but it's not nothing. Try to find out what that object is, so that you can then use a Python if-statement to check whether the return value you're getting is such an object. So, what I need to do is figure out a way to log the fact that no value is fetched. What I have currently, unfortunately, simply ignores the unfetchable value. As I stated before, I need to log the fact that no such value is obtained. Please...how do I do that?? Please be less vague. What part do you have a problem with? Checking whether no value is fetched or log the fact? No value is fetched because there is no value to fetch. I want to be able to log the fact that no value was fetched. How do I do that? Am I not being clear? Here, let me try again, as I began this thread with my first post. I thought it was so easy, so clear. If I use getfirst, I can set a default to log whether getfirst gets anything or not. I cannot do that with getlist. Is there a work-around? See above. Try to find out what kind of object it does return in the case that's causing you grief, and then devise a Python if-statement to test for that object. Hint: Use type() and repr() to find out what getlist() is returning. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: getlist question
On Fri, Dec 25, 2009 at 12:40 PM, Victor Subervi victorsube...@gmail.com wrote: It returns nothing. I believe I've stated that three times now. In Python, that's not possible. Every function returns something. If you think it returns nothing, it probably returns None. def foo() : pass ... a = foo() print a None -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I install GMPY 1.11 on a Mac with OS X 10.6 and Python 3.1?
On Dec 25, 9:25 am, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Fri, Dec 25, 2009 at 1:48 AM, Mensanator mensana...@aol.com wrote: On Dec 24, 10:18 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Thu, Dec 24, 2009 at 9:11 PM, Mensanator mensana...@aol.com wrote: Ok, so I got a MacBook Air. Has OS X 10.6 (Snow Leopard) and Python 2.6.1 already installed. So I install Xcode, download macports and download gmpy-1.11rc1. Following the instructions in mac_build.txt, I do the following: - sudo /opt/local/bin/port install gmp This works fine. Then I do - python setup.py install This also works (a few warnings, but nothing looked serious). Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. import gmpy gmpy.version() '1.11' python gmpy_test.py Unit tests for gmpy 1.11 on Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] Testing gmpy 1.11 (GMP 4.3.1), default caching (100, 128) gmpy_test_cvr 151 tests, 0 failures . . . 25 tests in gmpy_test_rnd.__test__.rand 1469 tests in 42 items. 1469 passed and 0 failed. Test passed. Looks like a viable gmpy module for 2.6. What do I do AFTER I install Python 3.1? Just running python3.1 from the same directory doesn't work. I've spent the last 5 days trying to figure that out. I hosed it so bad I somehow wrecked the 2.6 version to the point where it won't even load. I just got done doing a factory restore of the entire OS to undo everything I did. Re-did all the above and got it back working. Haven't re- installed 3.1 yet. Anbody have any idea how to make this work? Did you run setup.py with python3? Python 3.1 won't install itself as the default python install for compatibility reasons so you have to run python3 install setup.py to install it for that version of python. I wondered why there was both python3 and python3.1 in the bin directory. But why, when I type... $ python3 ...do I get... Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. [1]+ Stopped python3 I get the same result with python3.1. So, no, trying python3 is of no help, same errors as before. There's hundreds of them, but they start out $ /Library/Frameworks/Python.framework/Versions/3.1/bin/python3 setup.py install running install running build running build_ext building 'gmpy' extension creating build/temp.macosx-10.3-fat-3.1 creating build/temp.macosx-10.3-fat-3.1/src Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk Please check your Xcode installation gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -I./src -I/ opt/local/include -I/Library/Frameworks/Python.framework/Versions/3.1/ include/python3.1 -c src/gmpy.c -o build/temp.macosx-10.3-fat-3.1/src/ gmpy.o In file included from src/gmpy.c:206: /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:11:20: error: limits.h: No such file or directory /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:14:2: error: #error Something's broken. UCHAR_MAX should be defined in limits.h. /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:18: Any other ideas? Do I have to install a separate Python 3? That's not a Python 3 problem. It appears to be a problem in the build script. Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk My guess would be you're on Snow Leopard Yes, this machine has OS X 10.6. while the original developer is either on Tiger or Leopard. The script wants to use the 10.4 SDK but Apple only includes the SDKs for the latest 2 versions of OS X. Is there any easy way to fix the build script? Is there a hard way? Which files comprise the build script? Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: getlist question
On Fri, Dec 25, 2009 at 12:59 PM, Benjamin Kaplan benjamin.kap...@case.eduwrote: On Fri, Dec 25, 2009 at 12:40 PM, Victor Subervi victorsube...@gmail.com wrote: It returns nothing. I believe I've stated that three times now. In Python, that's not possible. Every function returns something. If you think it returns nothing, it probably returns None. def foo() : pass ... a = foo() print a None Thanks. It was returning an empty set which I have logged. beno -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I install GMPY 1.11 on a Mac with OS X 10.6 and Python 3.1?
On Fri, Dec 25, 2009 at 1:09 PM, Mensanator mensana...@aol.com wrote: On Dec 25, 9:25 am, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Fri, Dec 25, 2009 at 1:48 AM, Mensanator mensana...@aol.com wrote: On Dec 24, 10:18 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Thu, Dec 24, 2009 at 9:11 PM, Mensanator mensana...@aol.com wrote: Ok, so I got a MacBook Air. Has OS X 10.6 (Snow Leopard) and Python 2.6.1 already installed. So I install Xcode, download macports and download gmpy-1.11rc1. Following the instructions in mac_build.txt, I do the following: - sudo /opt/local/bin/port install gmp This works fine. Then I do - python setup.py install This also works (a few warnings, but nothing looked serious). Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. import gmpy gmpy.version() '1.11' python gmpy_test.py Unit tests for gmpy 1.11 on Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] Testing gmpy 1.11 (GMP 4.3.1), default caching (100, 128) gmpy_test_cvr 151 tests, 0 failures . . . 25 tests in gmpy_test_rnd.__test__.rand 1469 tests in 42 items. 1469 passed and 0 failed. Test passed. Looks like a viable gmpy module for 2.6. What do I do AFTER I install Python 3.1? Just running python3.1 from the same directory doesn't work. I've spent the last 5 days trying to figure that out. I hosed it so bad I somehow wrecked the 2.6 version to the point where it won't even load. I just got done doing a factory restore of the entire OS to undo everything I did. Re-did all the above and got it back working. Haven't re- installed 3.1 yet. Anbody have any idea how to make this work? Did you run setup.py with python3? Python 3.1 won't install itself as the default python install for compatibility reasons so you have to run python3 install setup.py to install it for that version of python. I wondered why there was both python3 and python3.1 in the bin directory. But why, when I type... $ python3 ...do I get... Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. [1]+ Stopped python3 I get the same result with python3.1. So, no, trying python3 is of no help, same errors as before. There's hundreds of them, but they start out $ /Library/Frameworks/Python.framework/Versions/3.1/bin/python3 setup.py install running install running build running build_ext building 'gmpy' extension creating build/temp.macosx-10.3-fat-3.1 creating build/temp.macosx-10.3-fat-3.1/src Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk Please check your Xcode installation gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -I./src -I/ opt/local/include -I/Library/Frameworks/Python.framework/Versions/3.1/ include/python3.1 -c src/gmpy.c -o build/temp.macosx-10.3-fat-3.1/src/ gmpy.o In file included from src/gmpy.c:206: /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:11:20: error: limits.h: No such file or directory /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:14:2: error: #error Something's broken. UCHAR_MAX should be defined in limits.h. /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:18: Any other ideas? Do I have to install a separate Python 3? That's not a Python 3 problem. It appears to be a problem in the build script. Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk My guess would be you're on Snow Leopard Yes, this machine has OS X 10.6. while the original developer is either on Tiger or Leopard. The script wants to use the 10.4 SDK but Apple only includes the SDKs for the latest 2 versions of OS X. Is there any easy way to fix the build script? Is there a hard way? Which files comprise the build script? Thanks for your help. I honestly have no idea how to fix this. I'm not very experienced with build scripts. I just noticed that I had the 10.4 SDK on Leopard but not on Snow Leopard and the script seems to want that version. My guess would be that the option is either in a setup.py file or a makefile in there. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I install GMPY 1.11 on a Mac with OS X 10.6 and Python 3.1?
On Dec 25, 9:25 am, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Fri, Dec 25, 2009 at 1:48 AM, Mensanator mensana...@aol.com wrote: On Dec 24, 10:18 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Thu, Dec 24, 2009 at 9:11 PM, Mensanator mensana...@aol.com wrote: Ok, so I got a MacBook Air. Has OS X 10.6 (Snow Leopard) and Python 2.6.1 already installed. So I install Xcode, download macports and download gmpy-1.11rc1. Following the instructions in mac_build.txt, I do the following: - sudo /opt/local/bin/port install gmp This works fine. Then I do - python setup.py install This also works (a few warnings, but nothing looked serious). Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. import gmpy gmpy.version() '1.11' python gmpy_test.py Unit tests for gmpy 1.11 on Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] Testing gmpy 1.11 (GMP 4.3.1), default caching (100, 128) gmpy_test_cvr 151 tests, 0 failures . . . 25 tests in gmpy_test_rnd.__test__.rand 1469 tests in 42 items. 1469 passed and 0 failed. Test passed. Looks like a viable gmpy module for 2.6. What do I do AFTER I install Python 3.1? Just running python3.1 from the same directory doesn't work. I've spent the last 5 days trying to figure that out. I hosed it so bad I somehow wrecked the 2.6 version to the point where it won't even load. I just got done doing a factory restore of the entire OS to undo everything I did. Re-did all the above and got it back working. Haven't re- installed 3.1 yet. Anbody have any idea how to make this work? Did you run setup.py with python3? Python 3.1 won't install itself as the default python install for compatibility reasons so you have to run python3 install setup.py to install it for that version of python. I wondered why there was both python3 and python3.1 in the bin directory. But why, when I type... $ python3 ...do I get... Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. [1]+ Stopped python3 I get the same result with python3.1. So, no, trying python3 is of no help, same errors as before. There's hundreds of them, but they start out $ /Library/Frameworks/Python.framework/Versions/3.1/bin/python3 setup.py install running install running build running build_ext building 'gmpy' extension creating build/temp.macosx-10.3-fat-3.1 creating build/temp.macosx-10.3-fat-3.1/src Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk Please check your Xcode installation gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -I./src -I/ opt/local/include -I/Library/Frameworks/Python.framework/Versions/3.1/ include/python3.1 -c src/gmpy.c -o build/temp.macosx-10.3-fat-3.1/src/ gmpy.o In file included from src/gmpy.c:206: /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:11:20: error: limits.h: No such file or directory /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:14:2: error: #error Something's broken. UCHAR_MAX should be defined in limits.h. /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:18: Any other ideas? Do I have to install a separate Python 3? That's not a Python 3 problem. It appears to be a problem in the build script. Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk My guess would be you're on Snow Leopard while the original developer is either on Tiger or Leopard. The script wants to use the 10.4 SDK but Apple only includes the SDKs for the latest 2 versions of OS X. I just thought of something. Why I am able to do the build for python 2.6? Wouldn't that also fail for lack of a 10.4 SDK? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl to Python conversion
In article 87zl5rnayz@crunchbang.belkin, Martin =?utf-8?B?U2Now7bDtm4=?= martin.sch...@gmail.com wrote: Problem: I have come across a small open source application that I find quite useful. It does have one major flaw though. Its output is in imperial units. Converting isn't a big deal for occasional use but if I start to use this stuff on a regular basis... I'd write an imperial to metric converter in Python ;-) -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommendation for small, fast, Python based web server
In article mailman.1720.1260539582.2873.python-l...@python.org, Antoine Pitrou solip...@pitrou.net wrote: Apparently you have debugged your speed issue so I suppose you don't have performance problems anymore. Do note, however, that Python is generally not as fast as C -- especially for low-level stuff -- and a Python Web server will probably serve around 10x less requests per second than a C Web server like Apache (this will still give you hundreds of simple requests per second on a modern machine). For static pages or dynamic pages? Once you get into dynamic pages, I sincerely doubt that the smaller Apache overhead makes lots of difference. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mechanize - Click a table row to navigate to detail page
On Fri, Dec 25, 2009 at 4:06 PM, Diez B. Roggisch de...@nospam.web.dewrote: Brian D schrieb: A search form returns a list of records embedded in a table. The user has to click on a table row to call a Javascript call that opens up the detail page. It's the detail page, of course, that really contains the useful information. How can I use Mechanize to click a row? You can't, if there is javascript involved. You can try use Firebug to see what the javascript eventually calls, with which parameters. Then construct that url based on the parameters in the table row's javascript (which of course you have to parse yourself out of the code) In firefox you can install LiveHttp Headers addon and can find the needed url. Diez -- http://mail.python.org/mailman/listinfo/python-list -- Regards, S.Selvam -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get the erroneous variable when getting a NameError exception?
On 25/12/2009 19:27, Gary Herron wrote: Dotan Barak wrote: Recover the exception, and examine the tuple of args or the message string. try: ... eval(my_number 10, {__builtins__:None}, {}) ... except NameError,e: ... print e.args ... print e.message ... (name 'my_number' is not defined,) name 'my_number' is not defined First of all, thank - I really appreciate your response. :) I must admit that i don't like the idea of parsing a string (if tomorrow the format of the message will change, i will be in a deep trouble ...). Is there is another way which doesn't involve string parsing? Thanks Dotan -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl to Python conversion
On Dec 13, 5:23 pm, martin.sch...@gmail.com (Martin Schöön) wrote: r0g aioe@technicalbloke.com writes: You'll probably find the majority of code in a GUI app is boring window handling stuff [...] Also, they probably didn't make it with QT which is fairly different from GTK. Tk is what they used. Well, on the surface then, it would seem that it might be easier to just use Python's included Tkinter for the GUI bits. However, PyQt is widely regarded as a nicer and more capable package. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Extra fields for logging
On 25 dic, 13:24, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Thu, 24 Dec 2009 05:06:48 -0800, Joan Miller wrote: I'm trying to add some extra fields to logging, I'm following this information [1] but it faills in my case. [...] I get = KeyError: 'host' Please post the entire traceback you get. -- Steven On 25 dic, 13:24, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Thu, 24 Dec 2009 05:06:48 -0800, Joan Miller wrote: I'm trying to add some extra fields to logging, I'm following this information [1] but it faills in my case. [...] I get = KeyError: 'host' Please post the entire traceback you get. -- Steven Traceback (most recent call last): File /usr/lib/python2.6/logging/__init__.py, line 768, in emit msg = self.format(record) File /usr/lib/python2.6/logging/__init__.py, line 648, in format return fmt.format(record) File /usr/lib/python2.6/logging/__init__.py, line 439, in format s = self._fmt % record.__dict__ KeyError: 'host' -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommendation for small, fast, Python based web server
This is a new wsgi web server implemented in a single file. http://code.google.com/p/web2py/source/browse/gluon/sneaky.py I could use some help with testing. Here is a version for Python 3.0 http://code.google.com/p/web2py/source/browse/gluon/sneaky.py Massimo On Dec 25, 12:38 pm, a...@pythoncraft.com (Aahz) wrote: In article mailman.1720.1260539582.2873.python-l...@python.org, Antoine Pitrou solip...@pitrou.net wrote: Apparently you have debugged your speed issue so I suppose you don't have performance problems anymore. Do note, however, that Python is generally not as fast as C -- especially for low-level stuff -- and a Python Web server will probably serve around 10x less requests per second than a C Web server like Apache (this will still give you hundreds of simple requests per second on a modern machine). For static pages or dynamic pages? Once you get into dynamic pages, I sincerely doubt that the smaller Apache overhead makes lots of difference. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Looking back over the years, after I learned Python I realized that I never really had enjoyed programming before. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get the erroneous variable when getting a NameError exception?
Dotan Barak wrote: On 25/12/2009 19:27, Gary Herron wrote: Dotan Barak wrote: Recover the exception, and examine the tuple of args or the message string. try: ... eval(my_number 10, {__builtins__:None}, {}) ... except NameError,e: ... print e.args ... print e.message ... (name 'my_number' is not defined,) name 'my_number' is not defined First of all, thank - I really appreciate your response. :) I must admit that i don't like the idea of parsing a string (if tomorrow the format of the message will change, i will be in a deep trouble ...). Is there is another way which doesn't involve string parsing? Thanks Dotan OK. Try this: Executing your code attempts to lookup variables in a local dictionary. You can rig up a local dictionary of your own choosing -- in this case, I have it print the name of any variable that is being looked up before actually doing the lookup.But at that point, you have what you want, that is, the name as a string -- you can do with it as you will -- record it, or print your nice error, or ... You probably want to change my def of __getitem__ to attempt the lookup first -- if that succeeds, return the value -- if it fails, then handle the error. Good luck, Gary Herron class D(dict): def __getitem__(self, name): print 'retrieving', name return dict.__getitem__(self,name) locals = D(b=123) # Defines b in a local dictionary exec(a=2*b, locals) # Looks up b in locals print locals['a'] # Returns the result (stored in 'a' in locals) locals = D() # Does not define b in the local dictionary exec(a=2*b, locals) # Fails to find b in locals -- http://mail.python.org/mailman/listinfo/python-list
Queues vs List
Was reading the official python document and I noticed they mentioned queues being more efficient for adding/removing elements vs list so I wrote a quick test the validate this claim and I wasn't very impressed by the results it seems queues are just slightly faster so my question to the list, is deque used much in python over general lists? 1 #!/usr/bin/python 2 3 import time 4 from collections import deque 5 6 nameList = [Eric,John,Michael] 7 #queue = deque([Eric,John,Michael]) 8 queue = deque(nameList) 9 10 def buildItems_q(q,n,mode): 11 start = 0 12 end = 0 13 14 if mode == 'q': 15 start = time.time() 16 for r in xrange(n): 17 queue.append(Terry_%s % r) 18 end = time.time() 19 20 while q.pop() is not None: 21 try: 22 q.pop() 23 except IndexError: 24 pass 25 break 26 else: 27 start = time.time() 28 for r in xrange(n): 29 q.append(Terry_%s % r) 30 end = time.time() 31 32 while q.pop() is not None: 33 try: 34 q.pop() 35 except IndexError: 36 pass 37 break 38 39 return (end - start) 40 41 if __name__ == __main__: 42 size = 1000 43 mode = 'list' 44 runtime = buildItems_q(queue,size,mode) 45 print Total run time: %f (%s) % (runtime,mode) 46 47 mode = 'Queue' 48 runtime = buildItems_q(queue,size,mode) 49 print Total run time: %f (%s) % (runtime,mode) rbr...@laptop:~/code/python$ python queue.py Total run time: 5.169290 (list) Total run time: 5.112517 (Queue) -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -- http://mail.python.org/mailman/listinfo/python-list
Re: Queues vs List
On 25Dec2009 17:21, Rodrick Brown rodrick.br...@gmail.com wrote: | Was reading the official python document and I noticed they mentioned queues | being more efficient for adding/removing elements vs list so I wrote a quick | test the validate this claim and I wasn't very impressed by the results it | seems queues are just slightly faster so my question to the list, is deque | used much in python over general lists? A deque has O(1) behaviour for adding or removing elements from the front or back of the deque. It has O(n) behaviour for lookups. A list has O(n) behaviour for adding/removing, roughly. It has O(1) behaviour for lookups. Removing from the front requires copying all the higher elements down, for example. Adding to the end _may_ cost a copy-the-whole-list if memory needs reallocating. But your lists/deques are VERY small. A deque is a more complicated structure (probably a linked list - I haven't checked). Its basic operation is more expensive and for your test cases probably overwhlems things. You need to use bigger test cases before the deque wins over the list, and of course a deque is only better than a list of your program has behaviour that is expensive for a list. Cheers, -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ Team work is essential. It gives the enemy other people to shoot at. - Murphy's Laws of Combat -- http://mail.python.org/mailman/listinfo/python-list
Re: Queues vs List
Rodrick Brown wrote: Was reading the official python document and I noticed they mentioned queues being more efficient for adding/removing elements vs list so I wrote a quick test the validate this claim and I wasn't very impressed by the results it seems queues are just slightly faster so my question to the list, is deque used much in python over general lists? 1 #!/usr/bin/python 2 3 import time 4 from collections import deque 5 6 nameList = [Eric,John,Michael] 7 #queue = deque([Eric,John,Michael]) 8 queue = deque(nameList) 9 10 def buildItems_q(q,n,mode): 11 start = 0 12 end = 0 13 14 if mode == 'q': 15 start = time.time() 16 for r in xrange(n): 17 queue.append(Terry_%s % r) 18 end = time.time() 19 20 while q.pop() is not None: 21 try: 22 q.pop() 23 except IndexError: 24 pass 25 break 26 else: 27 start = time.time() 28 for r in xrange(n): 29 q.append(Terry_%s % r) 30 end = time.time() 31 32 while q.pop() is not None: 33 try: 34 q.pop() 35 except IndexError: 36 pass 37 break 38 39 return (end - start) 40 41 if __name__ == __main__: 42 size = 1000 43 mode = 'list' 44 runtime = buildItems_q(queue,size,mode) 45 print Total run time: %f (%s) % (runtime,mode) 46 47 mode = 'Queue' 48 runtime = buildItems_q(queue,size,mode) 49 print Total run time: %f (%s) % (runtime,mode) rbr...@laptop:~/code/python$ python queue.py Total run time: 5.169290 (list) Total run time: 5.112517 (Queue) You're passing either 'list' or 'Queue' into buildItems_q(), but testing for 'q'. -- http://mail.python.org/mailman/listinfo/python-list
Re: getlist question
On Fri, 25 Dec 2009 12:59:20 -0500, Benjamin Kaplan wrote: On Fri, Dec 25, 2009 at 12:40 PM, Victor Subervi victorsube...@gmail.com wrote: It returns nothing. I believe I've stated that three times now. In Python, that's not possible. Every function returns something. Unless it raises an exception. If you think it returns nothing, it probably returns None. Very possibly, but this is Victor you're talking too, and as far as I can tell he hasn't shown his actual code. For all we know he has something like this: alist = [1, 2, 3] try: result = alist[100] except: pass print result See? Nothing is returned as the result. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I install GMPY 1.11 on a Mac with OS X 10.6 and Python 3.1?
On Fri, Dec 25, 2009 at 1:19 PM, Mensanator mensana...@aol.com wrote: On Dec 25, 9:25 am, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Fri, Dec 25, 2009 at 1:48 AM, Mensanator mensana...@aol.com wrote: On Dec 24, 10:18 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Thu, Dec 24, 2009 at 9:11 PM, Mensanator mensana...@aol.com wrote: Ok, so I got a MacBook Air. Has OS X 10.6 (Snow Leopard) and Python 2.6.1 already installed. So I install Xcode, download macports and download gmpy-1.11rc1. Following the instructions in mac_build.txt, I do the following: - sudo /opt/local/bin/port install gmp This works fine. Then I do - python setup.py install This also works (a few warnings, but nothing looked serious). Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. import gmpy gmpy.version() '1.11' python gmpy_test.py Unit tests for gmpy 1.11 on Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] Testing gmpy 1.11 (GMP 4.3.1), default caching (100, 128) gmpy_test_cvr 151 tests, 0 failures . . . 25 tests in gmpy_test_rnd.__test__.rand 1469 tests in 42 items. 1469 passed and 0 failed. Test passed. Looks like a viable gmpy module for 2.6. What do I do AFTER I install Python 3.1? Just running python3.1 from the same directory doesn't work. I've spent the last 5 days trying to figure that out. I hosed it so bad I somehow wrecked the 2.6 version to the point where it won't even load. I just got done doing a factory restore of the entire OS to undo everything I did. Re-did all the above and got it back working. Haven't re- installed 3.1 yet. Anbody have any idea how to make this work? Did you run setup.py with python3? Python 3.1 won't install itself as the default python install for compatibility reasons so you have to run python3 install setup.py to install it for that version of python. I wondered why there was both python3 and python3.1 in the bin directory. But why, when I type... $ python3 ...do I get... Python 3.1.1 (r311:74543, Aug 24 2009, 18:44:04) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type help, copyright, credits or license for more information. [1]+ Stopped python3 I get the same result with python3.1. So, no, trying python3 is of no help, same errors as before. There's hundreds of them, but they start out $ /Library/Frameworks/Python.framework/Versions/3.1/bin/python3 setup.py install running install running build running build_ext building 'gmpy' extension creating build/temp.macosx-10.3-fat-3.1 creating build/temp.macosx-10.3-fat-3.1/src Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk Please check your Xcode installation gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk - fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -I./src -I/ opt/local/include -I/Library/Frameworks/Python.framework/Versions/3.1/ include/python3.1 -c src/gmpy.c -o build/temp.macosx-10.3-fat-3.1/src/ gmpy.o In file included from src/gmpy.c:206: /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:11:20: error: limits.h: No such file or directory /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:14:2: error: #error Something's broken. UCHAR_MAX should be defined in limits.h. /Library/Frameworks/Python.framework/Versions/3.1/include/python3.1/ Python.h:18: Any other ideas? Do I have to install a separate Python 3? That's not a Python 3 problem. It appears to be a problem in the build script. Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/ MacOSX10.4u.sdk My guess would be you're on Snow Leopard while the original developer is either on Tiger or Leopard. The script wants to use the 10.4 SDK but Apple only includes the SDKs for the latest 2 versions of OS X. I just thought of something. Why I am able to do the build for python 2.6? Wouldn't that also fail for lack of a 10.4 SDK? I think you'd need different C sources for 2.x and 3.x because I think the C API changed quite a bit. That might be why it worked for 2.6 but failed for 3.1 -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
how to save a modified .xml back
Hi all, I want to load a small .xml file, modifiy some nodes and save the .xml with modifications to another .xml file. I managed to load and modify a small .xml file using xml.dom.minidom and xml.dom.pulldom. However, I don't know how to save it back using any of two modules. Any suggestion? Thank you in advance, ** from xml.dom.pulldom import START_ELEMENT, parse doc = parse('input.xml') for event, node in doc: if event == START_ELEMENT and node.localName == something_interesting: doc.expandNode(node) for an_element in node.childNodes: do_something() * Hyunchul -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get the erroneous variable when getting a NameError exception?
Dotan Barak wrote: div class=moz-text-flowed style=font-family: -moz-fixedOn 25/12/2009 19:27, Gary Herron wrote: Dotan Barak wrote: Recover the exception, and examine the tuple of args or the message string. try: ... eval(my_number 10, {__builtins__:None}, {}) ... except NameError,e: ... print e.args ... print e.message ... (name 'my_number' is not defined,) name 'my_number' is not defined First of all, thank - I really appreciate your response. :) I must admit that i don't like the idea of parsing a string (if tomorrow the format of the message will change, i will be in a deep trouble ...). Is there is another way which doesn't involve string parsing? Thanks Dotan /div I think there's a more fundamental question here. You're apparently looking to build your own error message instead of using the one already generated. But as you point out, you might end up parsing the existing error message in order to do that, and that's fragile coding. My take is that if you're using eval in your code, your user is clearly a programmer. So why are you not letting that programmer see the real error message, instead of trying to pretty it up? You can add to the message, but shouldn't need to hide the original one. To put it the other way around, if your user can't understand the python error messages, you should probably not be using unrestricted eval on something that user supplies. Lots more errors than NameError, and many of them are more subtle and dangerous. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: how to register with pypi - no such setup.py
On Dec 24, 3:32 am, Martin v. Loewis mar...@v.loewis.de wrote: Any tips? A binary distribution won't have a setup.py, because you can install it by other means (such as Windows Installer), instead of running setup.py What you want is a source distribution (sdist). Thanks. Yes, this is prob'ly documented somewhere. Now my next problem - how to get pypi.python.org to stop burning up version numbers each time I test this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Extra fields for logging
On Fri, 25 Dec 2009 12:07:20 -0800, Joan Miller wrote: On 25 dic, 13:24, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Thu, 24 Dec 2009 05:06:48 -0800, Joan Miller wrote: I'm trying to add some extra fields to logging, I'm following this information [1] but it faills in my case. [...] I get = KeyError: 'host' Please post the entire traceback you get. -- Steven Traceback (most recent call last): File /usr/lib/python2.6/logging/__init__.py, line 768, in emit msg = self.format(record) File /usr/lib/python2.6/logging/__init__.py, line 648, in format return fmt.format(record) File /usr/lib/python2.6/logging/__init__.py, line 439, in format s = self._fmt % record.__dict__ KeyError: 'host' Hmmm... that wasn't as helpful as I had hoped. Oh well. Going back to your earlier post, I can see a couple of problems. Firstly, your __getitem__ method always returns None. You need to return the result. Secondly, this works for me: import logging class ExtraInfo(object): def __getitem__(self, name): if name == 'host': result = 'foo' return result def __iter__(self): keys = ['host',] keys.extend(self.__dict__.keys()) return iter(keys) # better than keys.__iter__ def setup(filename='/tmp/foo.log'): log = logging.LoggerAdapter(logging.getLogger('foo'), ExtraInfo()) logging.basicConfig( level=logging.DEBUG, format=Date-Time: %(asctime)s Host: %(host)s %(levelname)s: %(message)s, datefmt=%Y-%m-%dT%H:%M:%S%z, filename=filename, filemode='w') return log log = setup() log.error('testing ...') log.debug('something happened') log.critical(it's the end of the world as we know it!) Hope this helps. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get the erroneous variable when getting a NameError exception?
On Fri, Dec 25, 2009 at 8:00 PM, Dave Angel da...@ieee.org wrote: Dotan Barak wrote: Recover the exception, and examine the tuple of args or the message string. try: ... eval(my_number 10, {__builtins__:None}, {}) ... except NameError,e: ... print e.args ... print e.message ... (name 'my_number' is not defined,) name 'my_number' is not defined I think there's a more fundamental question here. You're apparently looking to build your own error message instead of using the one already generated. But as you point out, you might end up parsing the existing error message in order to do that, and that's fragile coding. My take is that if you're using eval in your code, your user is clearly a programmer. So why are you not letting that programmer see the real error message, instead of trying to pretty it up? You can add to the message, but shouldn't need to hide the original one. To put it the other way around, if your user can't understand the python error messages, you should probably not be using unrestricted eval on something that user supplies. Lots more errors than NameError, and many of them are more subtle and dangerous. Hm, is this true, though? Is there anything subtle or dangerous possible here? He's using eval-- so no statements, its only an expression. He's passing in a 'globals' which has __builtins__ set to None, so this environment has access to -- basically nothing. Then the locals dictionary is empty as well, though I assume he'll fill it with things like my_number. Its sort of an interesting use for 'eval' that I hadn't ever considered before, really: ISTM that there's only three possible results.. a NameError, a SyntaxError, or a safely evaluated expression based on certain pre-defined objects. Okay, maybe one or two other simple exceptions if one tries to do strange things with dictionaries/etc in the expression. You can't even make it blow up to trigger a MemoryError, with some insane list comprehension because you don't even have access to range(). Unless he's passing an arbitrarily long string into the expression. I'm normally against eval -- but maybe I'm blind in not seeing the possible exploit or subtlety here in this eval-with-zero-access. --S -- http://mail.python.org/mailman/listinfo/python-list
menu and file
List, I want to read a file that has a list of data into a menu. User can pick up a line of data and execute it. For example, file has data like following 1 23 0x4530 2 42 0x8790 3 75 0x7684 . User can select line # and then execute hex data in that line. Any sample codes will be appreciated. Thanks! --henry -- http://mail.python.org/mailman/listinfo/python-list
[issue7481] Failing to start a thread leaves zombie thread in initial state
Changes by Nir Aides n...@winpdb.org: -- nosy: +nirai ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7481 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7006] The replacement suggested for callable(x) in py3k is not equivalent
Trundle andy-pyt...@hammerhartes.de added the comment: What Joe Amenta stumbled across is that ABCMeta caches its subclass checks. If you call ``isinstance(spam, Callable)`` and after that delete `type(spam).__call__`, every other call of ``isinstance(spam, Callable)`` will still return True. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7006 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7576] Avoid warnings in PyModuleDef_HEAD_INIT
New submission from Ronald Oussoren ronaldousso...@mac.com: When running GCC with warnings the compiler can warn about incomplete structure initializers. This gives spurious warnings when initializing a PyModuleDef structure using PyModuleDef_HEAD_INIT The attached patchs changes PyModuleDef_HEAD_INIT to explicitly initialize all fields in PyModuleDef_Base. An example warning that is silenced by this patch: Modules/objc/test/structpointer2.m:19: warning: missing initializer Modules/objc/test/structpointer2.m:19: warning: (near initialization for ‘mod_module.m_base.m_init’) -- files: moduleobject-init-warnings.patch keywords: needs review, patch, patch messages: 96881 nosy: ronaldoussoren priority: normal severity: normal stage: patch review status: open title: Avoid warnings in PyModuleDef_HEAD_INIT type: compile error versions: Python 3.2 Added file: http://bugs.python.org/file15672/moduleobject-init-warnings.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7576 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7006] The replacement suggested for callable(x) in py3k is not equivalent
Nick Coghlan ncogh...@gmail.com added the comment: Ah yes, I misread the example. Agreed that that is a change in behaviour then - it is possible to clear the caches if absolutely necessary, but doing so isn't particularly portable. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7006 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7006] The replacement suggested for callable(x) in py3k is not equivalent
Joe Amenta ament...@msu.edu added the comment: I believe that this patch works like you described... Attached a patch with more test cases to show this. (the [1:] parts are to make the test cases readable; they will still pass if all the leading newlines are removed from the triple-quoted strings and all [1:] are removed :-) -- Added file: http://bugs.python.org/file15673/new_callable_semantics_moretests.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7006 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7484] smtplib: verify breaks with Postfix servers
Pablo Mouzo pablomo...@gmail.com added the comment: This patch solves the problem with the VRFY command, but I'm still wondering if this happens with other commands too. -- keywords: +patch nosy: +pablomouzo Added file: http://bugs.python.org/file15674/issue7484-trunk.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7484 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7484] smtplib: verify breaks with Postfix servers
Changes by Pablo Mouzo pablomo...@gmail.com: Added file: http://bugs.python.org/file15675/issue7484-py3k.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7484 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7006] The replacement suggested for callable(x) in py3k is not equivalent
Joe Amenta ament...@msu.edu added the comment: To elaborate on my last comment: - touch_import looks for the required import binding in any scope, and it will add a global import if not found, otherwise it leaves it alone - the import added does not have a newline prefix, so if the newlines were left in, (without [1:]) the tests would fail. However, I found that the test cases are easier to read if they all start on the same indentation level, so adding a newline for the reader but telling the parser to ignore it makes readable, correct test cases. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7006 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6710] hotshot stats load causes TypeError when multiple files are loaded
Ezio Melotti ezio.melo...@gmail.com added the comment: The change that causes this problem has been introduced in r60149 to fix #1269. -- nosy: +ezio.melotti, georg.brandl, therve priority: - normal stage: - test needed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6710 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7519] ConfigParser can't read files with BOM markers
Changes by Benjamin Peterson benja...@python.org: -- title: CompileParser can't read files with BOM markers - ConfigParser can't read files with BOM markers ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7519 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com