Re: dict_to_xml
Hello, there is one simple example which I made for my needs - https://github.com/vojtarylko/dict2xml Regards, Vojtěch Dne 31.12.2011 6:48, Emeka napsal(a): Hello All, I have a dictionary object I would like to convert to xml. Could some assist with the link to libs to use? Or good examples. Regards, Janus -- /Satajanus Nig. Ltd / -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
Thank you for the reply. I had the same error message before and it was resolved when I removed a casting of a header value from unicode to str. Now in this case I can't see where that happens or what causes the error. The full trace I'm experiencing now is File "/media/Lexar/montao/google/appengine/runtime/wsgi.py", line 129, in _StartResponse raise InvalidResponseError('headers must be str') InvalidResponseError: headers must be str INFO 2011-12-31 04:55:36,484 recording.py:372] Saved; key: __appstats__:034800, part: 137 bytes, full: 27325 bytes, overhead: 0.001 + 0.008; link: http://localhost:8080/_ah/stats/details?time=1325307334890 ERROR2011-12-31 04:55:36,484 wsgi.py:186] Traceback (most recent call last): File "/media/Lexar/montao/google/appengine/runtime/wsgi.py", line 175, in Handle for chunk in result: File "/media/Lexar/montao/google/appengine/ext/appstats/recording.py", line 926, in appstats_wsgi_wrapper result = app(environ, appstats_start_response) File "/media/Lexar/montao/lib/webapp2/webapp2.py", line 1524, in __call__ return self._internal_error(e)(environ, start_response) File "/media/Lexar/montao/lib/webapp2/webapp2.py", line 1522, in __call__ return response(environ, start_response) File "/media/Lexar/montao/lib/webob/webob/__init__.py", line 2000, in __call__ start_response(self.status, self.headerlist) File "/media/Lexar/montao/google/appengine/ext/appstats/recording.py", line 923, in appstats_start_response return start_response(status, headers, exc_info) File "/media/Lexar/montao/google/appengine/runtime/wsgi.py", line 129, in _StartResponse raise InvalidResponseError('headers must be str') InvalidResponseError: headers must be str -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get function string name from i-th stack position?
On Dec 30, 11:48 pm, Ian Kelly wrote: > On Fri, Dec 30, 2011 at 11:43 AM, dmitrey wrote: > > Thank you. And what should I do to get function by itself instead of > > its string name, e.g. I want to know does this function is my_func or > > any other? For example, I would like to check is this function Python > > sum(), or maybe numpy.sum(), or anything else? > > The Python stack only includes Python code objects. Built-ins like > sum won't appear in it because they're basically C functions and don't > have associated code objects. If you really want to see them, you > could probably do something with ctypes to inspect the C stack, but I > don't recommend it. > > You can get the Python code objects from the stack by calling > inspect.stack(), which includes each frame object currently on the > stack as the first member of each tuple. E.g.: > > frames = map(operator.itemgetter(0), inspect.stack()) > > Each frame has an f_code attribute that stores the code object > associated with that frame. Getting the actual function from the code > object is tricky, for two reasons. One, not all code objects > represent functions. There are also code objects for modules, class > definitions, and probably other thing as well. Two, code objects > don't have associated functions. The relationship is the reverse: > functions have associated code objects. You would have to iterate > over each function that you're interested in, looking for one with a > func_code attribute that "is" the frame's f_code attribute. > > In any case, testing function identity is a rather large rabbit hole > that is best avoided. These are mathematically the same function: > > def plus1(value): > return value + 1 > > plus_one = lambda x: x + 1 > > But they are two distinct function objects, and there is no way > programmatically to determine that they are the same function except > by comparing the bytecode (which won't work generally because of the > halting problem). > > What is it that you're trying to do? Perhaps the helpful folks on the > list will be able to suggest a better solution if you can provide more > details. > > Cheers, > Ian Maybe it is somehow possible to compare function id with my candidates id, e.g. PythonSumID = id(sum) import numpy NumpySumID = id(numpy.sum) func = getting_function_from_Nth_stack_level_above if id(func) == PythonSumID: elif id(func) == NumpySumID: else: I need it due to the following reason: FuncDesigner users often use Python or numpy sum on FuncDesigner objects, while FuncDesigner.sum() is optimized for this case, works faster and doesn't lead to "Max recursion dept exceeded", that sometimes trigger for numpy or Python sum() when number of summarized elements is more than several hundreds. I would like to print warning "you'd better use FuncDesigner sum" if this case has been identified. Regards, D. -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
I can log the headers and it seems that they are strings: INFO 2011-12-31 08:43:03,286 paypal.py:143] headers: {'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON', 'X-PAYPAL-SECURITY-PASSWORD': '1324348659', 'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON', 'X-PAYPAL-SECURITY-SIGNATURE': 'Al6H7Bq3kp4bKFht2fR-p2FlAbp3AJFKl5pFMzHpo.QKYe4Uob5YPIm.', 'X-PAYPAL-SECURITY-USERID': 'niklas_1354859649_biz_api1.eddaconsult.se', 'X-PAYPAL-DEVICE-IPADDRESS': '127.0.0.1', 'X-PAYPAL-APPLICATION-ID': 'APP-80W284485P519543T'} -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
31.12.11 08:40, Steven D'Aprano написав(ла): 'JSON' is already a string. Calling str() on it is a waste of time. from __future__ import unicode_literals -- http://mail.python.org/mailman/listinfo/python-list
Re: Which library for audio playback ?
Fri, 30 Dec 2011 17:17:51 -0800 K Richard Pixley a écrit: > I made a similar survey of available libraries recently. I'm interested > in MIDI also, though, primarily on mac. > > There doesn't seem to be any definitive audio library for linux, > although several, (jack, oss, alsa), exist. (My impression is similar > to yours, OSS is obsolete. Jack may be the better library technically, > but is not as widely ported or available as ALSA.) > > There is a definitive library for both audio and MIDI on mac - core > audio. There really aren't any competitors. > > There is also a definitive library for windows, although I don't use > windows. It's the open source one with low latency that everyone in the > professional world uses to replace windows because, (surprise!), windows > isn't capable of coping. > > I have found python libraries for each of these, although some are very > low level libraries, basically just wrapping something even lower. If > anyone has done an integrated "full solution" for linux or mac, I didn't > find it. The closest I found was PortMIDI and PortAudio which appear to > have ports for all three platforms as well as one or two sets of python > bindings and seem to be high enough level to be both useful and > productive. The hard part there is that PortMIDI and PortAudio come in > source, which requires a bit of hunting to track down prerequisites, etc. > > Please keep us posted as I'm chasing a similar problem. Hi. Looking at it again, I've narrowed down to the following few : ossaudiodev http://docs.python.org/library/ossaudiodev.html Linux only but included in python pygame http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound Most occurring answer on forums and mailing-lists on the net for this question. Might be a little overkill... PortAudio http://people.csail.mit.edu/hubert/pyaudio/ http://www.portaudio.com/ Cross-platform, packaged for debian. Could fit my needs as well. Generally, the examples I find are about opening and playing a wavefile. I guess I'm gonna have to work a little to feed them a homegrown sinewave of arbitrary frequency. Regarding PortAudio, python /usr/share/doc/python-pyaudio/examples/system_info.py (and other examples) yield complaints about jack not being running. I assume they could be tweaked to use ALSA instead. I haven't had time to dig any further. If I come up with something, I'll keep you posted. Thanks for your answer. -- Jérôme -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get function string name from i-th stack position?
On 12/31/2011 08:48 AM, Ian Kelly wrote: But they are two distinct function objects, and there is no way programmatically to determine that they are the same function except by comparing the bytecode (which won't work generally because of the halting problem). Actually, it is often possible to determine that two functions are the same function, you simply need a to compare whether the function object lives in the same memory address. It is also possible to determine if two functions are different, if the function object are in different memory address than the function is different function. What is difficult to do due to the Halting problem is comparing whether two different functions are "equivalent" (and therefore interchangeable). I think the OP wants to find the former, not the latter. The former is trivial, the latter impossible. -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
On Sat, 31 Dec 2011 12:04:13 +0200, Serhiy Storchaka wrote: > 31.12.11 08:40, Steven D'Aprano написав(ла): >> 'JSON' is already a string. Calling str() on it is a waste of time. > > from __future__ import unicode_literals Fair point. Your correction is noted. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
I'm still no further to reaching a solution and my efforts of logging the headers didn't produce anything. I'm certain that it's upgrading from ptyhon 2.5 to python 2.7 that causes this since the GAE SDK uses WSGI instead of CGI now. Any idea about my problem? Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
On Sat, 31 Dec 2011 05:31:14 -0800, Niklas Rosencrantz wrote: > I'm still no further to reaching a solution and my efforts of logging > the headers didn't produce anything. I'm certain that it's upgrading > from ptyhon 2.5 to python 2.7 that causes this since the GAE SDK uses > WSGI instead of CGI now. Any idea about my problem? > > Thank you Have patience. It has been less than a day since you first asked, and it is New Years Day or New Years Eve (depending on where you are). Most people will be away from their computers or busy celebrating. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
funny minny year@@@@@@@@@@@@@@@@@@@@
http://123maza.com/48/silver424/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
On 2011-12-28, Steven D'Aprano wrote: > On Tue, 27 Dec 2011 18:42:05 -0800, Rick Johnson wrote: > >> I don't care what ANY dictionary says. Much less a "world" >> dictionary. I don't validate or invalidate a word based on some phony >> baloney group of pseudo intellectuals who decided one to day that >> writing a dictionary "might be cool". I am against these words and >> phrases because we already have words that work just fine. Why rock >> the boat? > > Why do you say "rock" when the word "shake" is just as good? > > Why do you say "boat" when we already have "ship"? > > Why do you say "pseudo intellectuals" when you could say "fake > intellectuals"? > > Why do I waste my time reading your pretentious self-important nonsense? http://xkcd.com/386/ ;) -- Grant Edwards grant.b.edwardsYow! Not SENSUOUS ... only at "FROLICSOME" ... and in gmail.comneed of DENTAL WORK ... in PAIN!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get function string name from i-th stack position?
On Sat, Dec 31, 2011 at 4:41 AM, Lie Ryan wrote: > On 12/31/2011 08:48 AM, Ian Kelly wrote: >> >> >> But they are two distinct function objects, and there is no way >> programmatically to determine that they are the same function except >> by comparing the bytecode (which won't work generally because of the >> halting problem). > > > Actually, it is often possible to determine that two functions are the same > function, you simply need a to compare whether the function object lives in > the same memory address. It is also possible to determine if two functions > are different, if the function object are in different memory address than > the function is different function. > > What is difficult to do due to the Halting problem is comparing whether two > different functions are "equivalent" (and therefore interchangeable). Yes, that is what I said. You can determine whether two function objects are the same, but not whether they are *mathematically* the same function. > I think the OP wants to find the former, not the latter. The former is > trivial, the latter impossible. Based on his subsequent clarification, I agree, although from his original post it sounded like he was just trying to identify summing functions in general. However, finding the built-in sum function on the stack is not trivial at all, perhaps not even possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get function string name from i-th stack position?
On Sat, Dec 31, 2011 at 1:44 AM, dmitrey wrote: > On Dec 30, 11:48 pm, Ian Kelly wrote: >> On Fri, Dec 30, 2011 at 11:43 AM, dmitrey wrote: >> > Thank you. And what should I do to get function by itself instead of >> > its string name, e.g. I want to know does this function is my_func or >> > any other? For example, I would like to check is this function Python >> > sum(), or maybe numpy.sum(), or anything else? >> >> The Python stack only includes Python code objects. Built-ins like >> sum won't appear in it because they're basically C functions and don't >> have associated code objects. If you really want to see them, you >> could probably do something with ctypes to inspect the C stack, but I >> don't recommend it. >> >> You can get the Python code objects from the stack by calling >> inspect.stack(), which includes each frame object currently on the >> stack as the first member of each tuple. E.g.: >> >> frames = map(operator.itemgetter(0), inspect.stack()) >> >> Each frame has an f_code attribute that stores the code object >> associated with that frame. Getting the actual function from the code >> object is tricky, for two reasons. One, not all code objects >> represent functions. There are also code objects for modules, class >> definitions, and probably other thing as well. Two, code objects >> don't have associated functions. The relationship is the reverse: >> functions have associated code objects. You would have to iterate >> over each function that you're interested in, looking for one with a >> func_code attribute that "is" the frame's f_code attribute. >> >> In any case, testing function identity is a rather large rabbit hole >> that is best avoided. These are mathematically the same function: >> >> def plus1(value): >> return value + 1 >> >> plus_one = lambda x: x + 1 >> >> But they are two distinct function objects, and there is no way >> programmatically to determine that they are the same function except >> by comparing the bytecode (which won't work generally because of the >> halting problem). >> >> What is it that you're trying to do? Perhaps the helpful folks on the >> list will be able to suggest a better solution if you can provide more >> details. >> >> Cheers, >> Ian > > Maybe it is somehow possible to compare function id with my candidates > id, e.g. > PythonSumID = id(sum) > import numpy > NumpySumID = id(numpy.sum) > func = getting_function_from_Nth_stack_level_above > if id(func) == PythonSumID: > > elif id(func) == NumpySumID: > > else: > > I need it due to the following reason: FuncDesigner users often use > Python or numpy sum on FuncDesigner objects, while FuncDesigner.sum() > is optimized for this case, works faster and doesn't lead to "Max > recursion dept exceeded", that sometimes trigger for numpy or Python > sum() when number of summarized elements is more than several > hundreds. I would like to print warning "you'd better use FuncDesigner > sum" if this case has been identified. The only think I can think of would be to replace the sum built-in with a wrapper that checks whether it's being called on FuncDesigner objects and issues a warning. Users might not like you messing with their built-ins in that way, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
In article , Grant Edwards wrote: > On 2011-12-28, Steven D'Aprano wrote: > > On Tue, 27 Dec 2011 18:42:05 -0800, Rick Johnson wrote: > > > >> I don't care what ANY dictionary says. Much less a "world" > >> dictionary. I don't validate or invalidate a word based on some phony > >> baloney group of pseudo intellectuals who decided one to day that > >> writing a dictionary "might be cool". I am against these words and > >> phrases because we already have words that work just fine. Why rock > >> the boat? > > > > Why do you say "rock" when the word "shake" is just as good? > > > > Why do you say "boat" when we already have "ship"? > > > > Why do you say "pseudo intellectuals" when you could say "fake > > intellectuals"? > > > > Why do I waste my time reading your pretentious self-important nonsense? > > http://xkcd.com/386/ > > ;) Why ROFLMAO when double-plus funny works just as well? -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On 12/31/2011 12:19 PM, davidfx wrote: > Should we always be using .format() for formatting strings or %? In new code, yes. %-style formatting will eventually go away, but probably not for a long time. > If I wanted to put .format into a variable, how would I do that. What do you mean? -- CPython 3.2.2 | Windows NT 6.1.7601.17640 -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
What exactly do you mean by putting .format into a variable? You mean like this: "{name} is very {adj} {gender}".format(name="sandy",adj="diligent",gender="female") Sat, 31 Dec 2011 20:19:34 +0200 tarihinde davidfx şöyle yazmış: Hello everyone, I just have a quick question about .format and %r %s %d. Should we always be using .format() for formatting strings or %? Example a = 'apples' print "I love {0}.".format(a) If I wanted to put .format into a variable, how would I do that. Thanks for your information in advance. David -- Opera'nın e-posta istemcisi ile gönderildi: http://www.opera.com/mail -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) What is the .format version of this concept? -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
You mean like this? === a = "I like {name}" a.format(name="myself") 'I like myself' Sat, 31 Dec 2011 20:44:08 +0200 tarihinde davidfx şöyle yazmış: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) What is the .format version of this concept? -- Opera'nın e-posta istemcisi ile gönderildi: http://www.opera.com/mail -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
How 'bout just: >>> s = "{0} {1} {2} {3}" >>> s.format(1, 2, 3, 4) '1 2 3 4' Evan On 12/31/2011 13:44, davidfx wrote: > Thanks for your response. I know the following code is not going to be > correct but I want to show you what I was thinking. > > formatter = "%r %r %r %r" > > print formatter % (1, 2, 3, 4) > > What is the .format version of this concept? > signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On Dec 31, 2011 1:46 PM, "davidfx" wrote: > > Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. > > formatter = "%r %r %r %r" > > print formatter % (1, 2, 3, 4) > > What is the .format version of this concept? > format is a method of the string class. You store the string the same way you would any other. formatter = "Hello, {}" print(formatter.format("world")) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
On 31.12.2011 19:23, Roy Smith wrote: Why do I waste my time reading your pretentious self-important nonsense? http://xkcd.com/386/ ;) Why ROFLMAO when double-plus funny works just as well? xkcd/386 has been the excuse for replying to RR for ages and I still don't understand why he gets that much advertence. Charity? Sympathy for the lone and broken? FWIW, it undermines all my attempts to block him. Sigh. -- http://mail.python.org/mailman/listinfo/python-list
Python powering giant screen in Times Square
Verizon has a giant HD screen in Times Square today showing a live feed of social media activity – and it's built entirely in Python. Our app, FeedMagnet, aggregates and curates social content and is powering the screen. It has a Django front-end and pure Python backend to talk to Facebook, Twitter, Instagram, Google+, Foursquare, and other sources. So if you happen to be in Times Square for the crazy party today, tell the people around you that big social media screen is powered by Python! - Jason (founder of FeedMagnet) -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On 31.12.2011 19:44, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) What is the .format version of this concept? formatter = "{0} {1} {2} {3}" formatter.format(1,2,3,4) I have to say, I simply hate .format(), and I will be very, very upset if classic formatting will really be removed. I understand that .format() has a lot of advantages for more complex formatting, but for the simple stuff I usually do, it's just terribly inconvenient (try {} on a German keyboard). -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On 12/31/11 12:57, Benjamin Kaplan wrote: format is a method of the string class. You store the string the same way you would any other. formatter = "Hello, {}" print(formatter.format("world")) Just to note that this syntax doesn't quite work in some earlier versions (tested below in 2.6, which came stock in Debian Stable) >>> formatter = "Hello, {}" >>> print(formatter.format("world")) Traceback (most recent call last): File "", line 1, in ValueError: zero length field name in format It needs to be spelled "{0}" -tkc -- http://mail.python.org/mailman/listinfo/python-list
python curses wrapper
Hello, I have been struggling reseting the terminal when I try to do KeyboardInterrupt exception therefore I read the documentation for curses.wrapper and it seems to take care of it for me, http://docs.python.org/library/curses.html#curses.wrapper. Can someone please provide a Hello World example with python curses wrapper? tia -- http://mail.python.org/mailman/listinfo/python-list
Re: python curses wrapper
On 31.12.2011 20:24, Mag Gam wrote: Hello, I have been struggling reseting the terminal when I try to do KeyboardInterrupt exception therefore I read the documentation for curses.wrapper and it seems to take care of it for me, http://docs.python.org/library/curses.html#curses.wrapper. Can someone please provide a Hello World example with python curses wrapper? tia Use atexit.register() to register a cleanup function which is called when the program exits: import atexit import curses def cleanup(): curses.nocbreak() stdscr.keypad(0) curses.echo() curses.endwin() atexit.register(cleanup) stdscr = curses.initscr() curses.noecho() curses.cbreak() stdscr.keypad(1) curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) stdscr.bkgd(curses.color_pair(1)) stdscr.refresh() win = curses.newwin(5, 20, 5, 5) win.bkgd(curses.color_pair(2)) win.box() win.addstr(2, 2, "Hallo, Welt!") win.refresh() c = stdscr.getch() -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On 01/01/2012 05:44 AM, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) What is the .format version of this concept? I don't think the (%r)epr-formatting exist anymore, so if you want to do that you'll need to call repr manually. -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On 12/31/11 7:34 PM, Lie Ryan wrote: On 01/01/2012 05:44 AM, davidfx wrote: Thanks for your response. I know the following code is not going to be correct but I want to show you what I was thinking. formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) What is the .format version of this concept? I don't think the (%r)epr-formatting exist anymore, so if you want to do that you'll need to call repr manually. Yes, it does. formatter = '{!r} {!r} {!r} {!r}' print formatter.format(1,2,3,4) -- 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: python curses wrapper
On 31.12.2011 20:34, Alexander Kapps wrote: On 31.12.2011 20:24, Mag Gam wrote: Hello, I have been struggling reseting the terminal when I try to do KeyboardInterrupt exception therefore I read the documentation for curses.wrapper and it seems to take care of it for me, http://docs.python.org/library/curses.html#curses.wrapper. Can someone please provide a Hello World example with python curses wrapper? tia Use atexit.register() to register a cleanup function which is called when the program exits: Oh, sorry, I missed the curses.wrapper() part. Here is an example: import curses def main(screen): curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLUE) curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) screen.bkgd(curses.color_pair(1)) screen.refresh() win = curses.newwin(5, 20, 5, 5) win.bkgd(curses.color_pair(2)) win.box() win.addstr(2, 2, "Hallo, Welt!") win.refresh() c = screen.getch() try: curses.wrapper(main) except KeyboardInterrupt: print "Got KeyboardInterrupt exception. Exiting..." exit() -- http://mail.python.org/mailman/listinfo/python-list
Re: python curses wrapper
thanks for your prompt reply. Why would I have to use atexeit? According to the documentation, curses.wrapper should handle what cleanup() should be doing. Neverthless, good to know it exists :p On Sat, Dec 31, 2011 at 2:34 PM, Alexander Kapps wrote: > On 31.12.2011 20:24, Mag Gam wrote: >> >> Hello, >> >> I have been struggling reseting the terminal when I try to do >> KeyboardInterrupt exception therefore I read the documentation for >> curses.wrapper and it seems to take care of it for me, >> http://docs.python.org/library/curses.html#curses.wrapper. >> >> Can someone please provide a Hello World example with python curses >> wrapper? >> >> tia > > > Use atexit.register() to register a cleanup function which is called when > the program exits: > > import atexit > import curses > > def cleanup(): > curses.nocbreak() > stdscr.keypad(0) > curses.echo() > curses.endwin() > > atexit.register(cleanup) > > stdscr = curses.initscr() > curses.noecho() > curses.cbreak() > stdscr.keypad(1) > > curses.start_color() > curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLUE) > curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) > > stdscr.bkgd(curses.color_pair(1)) > stdscr.refresh() > > win = curses.newwin(5, 20, 5, 5) > win.bkgd(curses.color_pair(2)) > win.box() > win.addstr(2, 2, "Hallo, Welt!") > win.refresh() > > c = stdscr.getch() > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Best Way To Bound Function Execution Time
I am writing some paramiko-based ssh routines. One of them logs into a remote server and then does a sudo command. The problem is that if the user provides the incorrect sudo password, the call hangs the other end is waiting for the correct password to be entered. Is there some standard Pythonic way to bound how long a function call can run, after which time it is forcefully terminated? TIA, -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python powering giant screen in Times Square
On Sat, Dec 31, 2011 at 12:05 PM, Jason Ford wrote: > Verizon has a giant HD screen in Times Square today showing a live > feed of social media activity – and it's built entirely in Python. > > Our app, FeedMagnet, aggregates and curates social content and is > powering the screen. It has a Django front-end and pure Python backend > to talk to Facebook, Twitter, Instagram, Google+, Foursquare, and > other sources. > > So if you happen to be in Times Square for the crazy party today, tell > the people around you that big social media screen is powered by > Python! Wow! That's awesome. Thanks for sharing this! -eric > > - Jason (founder of FeedMagnet) > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: mutually exclusive arguments to a constructor
On 2011-12-30, Roy Smith wrote: > "But!", some C++/Java type bondage addicts might cry, "there's nothing > to prevent somebody from creating a DirectionIndicatingThingie directly, > bypassing the factory functions. There's no way to make the constructor > private!". To which the free-willed pythonistas would respond, "If it > hurts when you do that, don't do that". Actually one problem that can occur in large Java projects is that the package structure requires some things to have public constructors (even when you'd rather not do that) so the Factory class in the main package has access to them. -- English has perfect phonetic spelling. It just doesn't have phonetic pronunciation.[Peter Moylan] -- http://mail.python.org/mailman/listinfo/python-list
Re: mutually exclusive arguments to a constructor
On 2011-12-30, Günther Dietrich wrote: > Adam Funk wrote: > >>Suppose I'm creating a class that represents a bearing or azimuth, >>created either from a string of traditional bearing notation >>("N24d30mE") or from a number indicating the angle in degrees as >>usually measured in trigonometry (65.5, measured counter-clockwise >>from the x-axis). The class will have methods to return the same >>bearing in various formats. ... > You can determine the type of the input data by using isinstance() and > take the appropriate actions depending on this decision: > class MyClass(object): > ... def __init__(self, input_data): > ... if isinstance(input_data, basestring): > ... print "Do actions for string type input" > ... elif isinstance(input_data, float): > ... print "Do actions for float type input" > ... def get_output_data(self): > ... return "output data" Aha, I think I like this approach best, partly because I realized after writing my post that it might also be good to accept strings representing "pure" angles (e.g., "65d30m"). So I think I'll use isinstance *and then* check the input string against some regexes to determine whether it's in traditional surveying notation or trig notation in DMS. -- The generation of random numbers is too important to be left to chance. [Robert R. Coveyou] -- http://mail.python.org/mailman/listinfo/python-list
Re: .format vs. %
On 12/31/2011 2:24 PM, Tim Chase wrote: On 12/31/11 12:57, Benjamin Kaplan wrote: format is a method of the string class. You store the string the same way you would any other. formatter = "Hello, {}" print(formatter.format("world")) Just to note that this syntax doesn't quite work in some earlier versions (tested below in 2.6, which came stock in Debian Stable) Autonumbering of {} was introduced, at my suggestion, in 3.1 and included with 2.7 (I presume). >>> formatter = "Hello, {}" >>> print(formatter.format("world")) Traceback (most recent call last): File "", line 1, in ValueError: zero length field name in format It needs to be spelled "{0}" -tkc -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python powering giant screen in Times Square
On 12/31/2011 2:05 PM, Jason Ford wrote: Verizon has a giant HD screen in Times Square today showing a live feed of social media activity – and it's built entirely in Python. Our app, FeedMagnet, aggregates and curates social content and is powering the screen. It has a Django front-end and pure Python backend to talk to Facebook, Twitter, Instagram, Google+, Foursquare, and other sources. So if you happen to be in Times Square for the crazy party today, tell the people around you that big social media screen is powered by Python! Great! I will look for it on the TV broadcasts. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
[Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs
Hi! I'm working on a script utilizing os.makedirs to make directories to which I'm then trying to write files created by exe's spawned w/ subprocess.call; I'm developing in Stani's Python Editor, debugging using Winpdb. I've gotten to the point where subprocess.Popen._execute_child is raising a WindowsError(5,'Access is denied') exception. I've tried: setting the mode in the makedirs call; using os.chmod(, stat.S_IWRITE); and even setting a breakpoint before the subprocess.call and unsetting the read-only attribute of the pertinent directory tree using the Windows directory Properties dialog--which doesn't "take," if that's a clue--all to no avail. I suspect that maybe it has to do w/ not running Winpdb as administrator, but I'm not sure how to do that when starting Winpdb from w/in SPE, and in any event, it doesn't seem reasonable that there's no way to get this to work w/in the script itself. Please help! -- http://mail.python.org/mailman/listinfo/python-list
Re: PySide / PyQt autocompletion in IDEs
On Thu, Dec 29, 2011 at 6:22 PM, Merwin wrote: > Hi, > > I would like to work with PyQt / PySide, but there is a small problem : > methods arguments are not completed by IDE's autocompletion. > > When, typing "PySide.", I correctly get the module's attributes, but when I > want to see what arguments are expected to a constructor / method, all I get > is *args, **kwargs. > > I perfectly understand why this happen, but do you know a way to get around > this ? > > I spend more time looking for arguments in Qt's documentation than > effectively programming, which is a problem :-/ In PyDev you can use a .api file (the same from QScintilla) to be used for the code-completion. Take a look at: http://pydev.org/manual_101_interpreter.html for details (I know it's available for PyQt, but I'm not sure about PySide, but if it's not, maybe it can be requested for the PySide guys). Cheers, Fabio -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Way To Bound Function Execution Time
Tim Daneliuk writes: > Is there some standard Pythonic way to bound how long a function > call can run, after which time it is forcefully terminated? Basically, run it in a separate process and use os.kill to kill it. -- http://mail.python.org/mailman/listinfo/python-list
Re: InvalidResponseError: headers must be str
Thanks for the replies here. I will have patience but this bug is blocking my integration efforts. I tried logging the TCP packets with tcpdump and nothing special appeared. Niklas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
On 2011-12-31, Alexander Kapps wrote: > On 31.12.2011 19:23, Roy Smith wrote: > Why do I waste my time reading your pretentious self-important nonsense? >>> >>> http://xkcd.com/386/ >>> >>> ;) >> >> Why ROFLMAO when double-plus funny works just as well? > > xkcd/386 has been the excuse for replying to RR for ages and I still > don't understand why he gets that much advertence. Charity? Sympathy > for the lone and broken? Sadly, RR's post are often (in the supposed words of Wolfgang Pauli) "not even wrong". -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
On 01.01.2012 03:36, Grant Edwards wrote: On 2011-12-31, Alexander Kapps wrote: On 31.12.2011 19:23, Roy Smith wrote: Why do I waste my time reading your pretentious self-important nonsense? http://xkcd.com/386/ ;) Why ROFLMAO when double-plus funny works just as well? xkcd/386 has been the excuse for replying to RR for ages and I still don't understand why he gets that much advertence. Charity? Sympathy for the lone and broken? Sadly, RR's post are often (in the supposed words of Wolfgang Pauli) "not even wrong". I'm sure, RR is now jumping up high in rapture for being compared to high-profile scientist geniuses. Move fuel for his self-affirmation. I'll give my entire kingdom (or important body-parts, in case my kingdom isn't enough) if people would just understand that perfection(ists) is/are *the most* dangerous thing possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
On 12/27/2011 6:42 PM, Rick Johnson wrote: On Dec 27, 8:21 pm, Tim Chase wrote: I'm glad you're open to learning more about English as "used to" is perfectly acceptable according to the World English Dictionary[1] [...] May you be found better for learning and come to give others the benefit of the doubt. I don't care what ANY dictionary says. Much less a "world" dictionary. (Shouldn't this be |||world|||?) I don't validate or invalidate a word based on some phony baloney I doubt you could validate or invalidate a word. A word is, there is no validation necessary. You could potentially try to validate it's use but again that's not in your power. group of pseudo intellectuals who decided one to day that writing a dictionary "might be cool". I think you need to go back to school to understand what a dictionary is. (FYI, a dictionary codifies usage, not the other way around.) I am against these words and phrases I think you mean these words and phrases being used in this way - the words and phrases themselves are just that. They imply no meaning unless used in some kind of context. because we already have words that work just fine. Why rock the boat? Perhaps you mean, because more precise words or phrases for these uses exist? By your token 'work' should refer to physical activity which is not appropriate in this context and probably 'fine' should refer to a payment that is made having broken some rule or regulation thus leading to monetary reparation. I think, herein lies the problem - abject denial of all evidence to the contrary simply because it disagrees with your limited point of view. Why would you use a word like "hard" (which describes the physical properties of a tangible object), Because many words have more than one meaning and their context describes the meaning. For example 'Time flies like an arrow, fruit flies like a banana'. I know you can parse and understand that but the sentences are precisely alike, yet completely different. to describe how "difficult" a task may be? Because it's a perfectly legitimate thing to do. Many problems are described as 'HARD' in technical documentation when examining their complexity. I don't always like the terms used for things, but at least let's be consistent in our usage. If you insist on this lunacy, then why not use "soft" to describe how easy a task may be? Seems ridiculous now, huh? Soft is used in this context - as in choosing the soft option - i.e. the easy way out. And your problem is, precisely? Garbage Verbiage Translator: For Garbage Verbiage, read 'common English' Used to -> previously|before Though used to is perfect acceptable in any English speaking country. Supposed to -> required|expected probably 'intended' would be better here since 'supposed to' indicates that you should do this, but it is not required (pretty much the opposite for your given translation). Use to -> accustomed|acquainted Sorry to be picky, but "use to" refers to application as in "When I say 'idiot', in this context 'idiot' I use to mean 'person who cannot speak English as it is commonly used'.", not accustomed|acquainted. In the example you give, it's probably mistyped, maybe by a non-native English speaker. (oh bother, I just used " and ' to denote separate spoken phrases, maybe I should use ||| instead.) For what it's worth in English (i.e. British, the language I was brought up to speak) we say, for example: * get on/off a bus * get up in the morning * get down to some music * get around an obstacle * get over a broken relationship * get back to our previous place in a story * get through a difficult time/bush * get into a really good book * get about town * put up our Christmas lights and put down an idiot that doesn't understand that English has lots of compound verbs that are not poorly written, just commonly used and understood. Right (OOC) -> Correct While I agree 'right' can be annoying it's usage as in 'you are correct' can be traced back to 1588, I think we're going to have to allow for it's usage in 2011 (very nearly 2012 for me and definitely 2012 for anyone east of New York City). Hard (OOC) -> Difficult Phrases to mean 'difficult' or 'tough' come from at least 1886 so again, it's use in this context is hardly new. (And remember Charles Dickens' book Hard Times uses 'hard' to mean difficult not physically solid.) In fact looking into this a little more carefully, "hard of hearing" maintains the now largely obsolete meaning of hard from Middle English to mean have difficult doing something. I don't really think we can claim it's usage is wrong. Pretty (OOC) -> very Pretty on it's own doesn't mean very at all. (God knows where you got that idea from.) When combined with another adjective, such as hard, pretty does enhance the adjective. However, pretty difficult is not the same as very difficult. Pretty, in this context would prob
Re: Python education survey
On 12/31/2011 1:06 PM, Alexander Kapps wrote: > xkcd/386 has been the excuse for replying to RR for ages and I still > don't understand why he gets that much advertence. Charity? Sympathy > for the lone and broken? > > FWIW, it undermines all my attempts to block him. Sigh. Do what I do: laugh at the joke. He's a troll and the posts are jokes. Personally, I enjoy his posts; the silliness is good for a laugh. Once you stop taking it seriously, it goes from irritation to entertainment. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python education survey
On Sun, Jan 1, 2012 at 4:12 PM, Dominic Binks wrote: > While I agree 'right' can be annoying it's usage as in 'you are correct' can > be traced back to 1588, I think we're going to have to allow for it's usage > in 2011 (very nearly 2012 for me and definitely 2012 for anyone east of New > York City). And I am right, And you are right, And everything is quite correct! -- http://math.boisestate.edu/gas/mikado/webopera/mk103.html Context matters, words have multiple meanings. Can we agree on this point and move on? Otherwise, we're still going to be arguing this come 2013... ChrisA -- http://mail.python.org/mailman/listinfo/python-list