Re: tornado.web ioloop add_timeout eats CPU
What's wrong is the 1,135,775 calls to "method 'poll' of 'select.epoll' objects". I was affraid you are going to say that. :-) With five browsers waiting for messages over 845 seconds, that works out to each waiting browser inducing 269 epolls per second. Almost equally important is what the problem is *not*. The problem is *not* spending the vast majority of time in epoll; that's *good* news. The problem is *not* that CPU load goes up linearly as we connect more clients. This is an efficiency problem, not a scaling problem. So what's the fix? I'm not a Tornado user; I don't have a patch. Obviously Laszlo's polling strategy is not performing, and the solution is to adopt the event-driven approach that epoll and Tornado do well. Actually, I have found a way to overcome this problem, and it seems to be working. Instead of calling add_timeout from every request, I save the request objects in a list, and operate a "message distributor" service in the background that routes messages to clients, and finish their long poll requests when needed. The main point is that the "message distributor" has a single entry point, and it is called back at given intervals. So the number of callbacks per second does not increase with the number of clients. Now the CPU load is about 1% with one client, and it is the same with 15 clients. While the response time is the same (50-100msec). It is efficient enough for me. I understand that most people do a different approach: they do a fast poll request from the browser in every 2 seconds or so. But this is not good for me, because then it can take 2 seconds to send a message from one browser into another that is not acceptable in my case. Implementing long polls with a threaded server would be trivial, but a threaded server cannot handle 100+ simultaneous (long running) requests, because that would require 100+ threads to be running. This central "message distributor" concept seems to be working. About 1-2% CPU overhead I have to pay for being able to send messages from one browser into another within 100msec, which is fine. I could have not done this without your help. Thank you! Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 04/09/2012 05:56, Dan Sommers wrote: That said, if I really wanted bloodshed, I would propose = for the third string-equality operator! ;-) Dan Dan "agent provocateur" Sommers? :) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 04/09/2012 02:54, Roy Smith wrote: There's been a bunch of threads lately about string implementations, and that got me thinking (which is often a dangerous thing). Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. But, if it turns out that for real-life situations, the ends of strings have more entropy than the beginnings, the odds are you'll discover that they're unequal quicker by starting at the end. It doesn't seem un-plausible that this is the case. For example, most of the filenames I work with begin with "/home/roy/". Most of the strings I use as memcache keys have one of a small number of prefixes. Most of the strings I use as logger names have common leading substrings. Things like credit card and telephone numbers tend to have much more entropy in the trailing digits. On the other hand, hostnames (and thus email addresses) exhibit the opposite pattern. Anyway, it's just a thought. Has anybody studied this for real-life usage patterns? I'm also not sure how this work with all the possible UCS/UTF encodings. With some of them, you may get the encoding semantics wrong if you don't start from the front. Good grief, what timing!!! The dust has yet to settle over the "Flexible string representation, unicode, typography, ..." thread and you ask this. I'll just cross my fingers and hope that people stick with facts, realistic benchmarks etc, and not good old fashioned FUD. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: tornado.web ioloop add_timeout eats CPU
Laszlo Nagy writes: > but a threaded server cannot handle 100+ simultaneous (long running) > requests, because that would require 100+ threads to be running. On a reasonable server these days, 100 threads seems to be no big deal. I've run several times that many. I think things get ragged at a few thousand threads. -- http://mail.python.org/mailman/listinfo/python-list
focus on jtextfield
how do I know if a JTextField has the focus? thank to all -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
Roy Smith writes: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're > down to the O(n) part of comparing every character. > > I'm wondering if it might be faster to start at the ends of the strings > instead of at the beginning? If the strings are indeed equal, it's the > same amount of work starting from either end. But, if it turns out that > for real-life situations, the ends of strings have more entropy than the > beginnings, the odds are you'll discover that they're unequal quicker by > starting at the end. I guess we all have examples with specific entropy distribution. Going backwards on long strings can be profitable with file paths. If that is the case, and if you spend a lot of time comparing strings, why not store them in reverse? > It doesn't seem un-plausible that this is the case. For example, most > of the filenames I work with begin with "/home/roy/". Most of the > strings I use as memcache keys have one of a small number of prefixes. > Most of the strings I use as logger names have common leading > substrings. In that case I would split the paths, and use some sort of string-id, or use intern() and then compare components with "is" instead of "==". (Basically, turning the string of chars into a strings of ids/ints/pointers.) > Things like credit card and telephone numbers tend to have much more > entropy in the trailing digits. On the other hand, hostnames (and thus > email addresses) exhibit the opposite pattern. Yes, real-world is a mess. > Anyway, it's just a thought. Has anybody studied this for real-life > usage patterns? I've tried the "intern()" trick several times with lists of strings, and was satisfied, but this was in specific cases (with a finite set of strings). For "short" strings of chars (up to, say a hundred of characters), I've never found anything significantly faster than the default sweep (that was in C/C++, not python). For longer and/or more structured strings/lists, making use of the structure is a good idea, but I see no general pattern here (as you note). > I'm also not sure how this work with all the possible UCS/UTF encodings. > With some of them, you may get the encoding semantics wrong if you don't > start from the front. If you're testing for equality, I can't see how this could matter, even with variable-length encodings. If you're comparing different encodings, then you need different access methods to random characters (but this doesn't affect the algorithm). If you're using variable-length encoding, e.g., UTF-8, accessing at a specific position is not possible. -- Alain. -- http://mail.python.org/mailman/listinfo/python-list
Re: calling loaded DLL function expecting POINT * argument
On Sunday, August 26, 2012 9:23:49 PM UTC-4, Tim Roberts wrote: > Tim Williams wrote: > > > > >Hello all, > > > > > >I'm trying to use the ctypes module to call functions in a DLL. I've > > >figured out how to modify my path so the library is found, and I can > > >call LoadLibrary on it, but one of the functions expects an array of > > > POINTS. Here is the prototype from the .h file: > > > > > > > > >TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int nHeight, > >POINT* ptMasks, int nNumPoints); > > > > How is TRACKER_API defined? You're using ctypes.oledll, which uses the > > __stdcall calling convention. It's possible your DLL is defined as > > __cdecl. Try cdll.LoadLibrary instead of oledll.LoadLibrary. > > -- > > Tim Roberts, t...@probo.com > > Providenza & Boekelheide, Inc. Thanks for the reply. I've been out all last week. I'll give it a try. -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On 04.09.12 04:13, Steven D'Aprano wrote: Why does the open builtin need this added complexity? Why not just call os.open directly? Or for more complex openers, just call the opener directly? What is the rationale for complicating open instead of telling people to just call their opener directly? See http://bugs.python.org/issue12797. -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On 03.09.12 15:32, Marco wrote: Does anyone have an example of utilisation? http://bugs.python.org/issue13424 -- http://mail.python.org/mailman/listinfo/python-list
Re: calling loaded DLL function expecting POINT * argument
On Tuesday, September 4, 2012 8:16:33 AM UTC-4, Tim Williams wrote: > On Sunday, August 26, 2012 9:23:49 PM UTC-4, Tim Roberts wrote: > > > Tim Williams wrote: > > > > > > > > > > > > >Hello all, > > > > > > > > > > > > > >I'm trying to use the ctypes module to call functions in a DLL. I've > > > > > > >figured out how to modify my path so the library is found, and I can > > > > > > >call LoadLibrary on it, but one of the functions expects an array of > > > > > > > POINTS. Here is the prototype from the .h file: > > > > > > > > > > > > > > > > > > > > >TRACKER_API HRESULT InitializeMask(HANDLE pHandle, int nWidth, int > > >nHeight, POINT* ptMasks, int nNumPoints); > > > > > > > > > > > > How is TRACKER_API defined? You're using ctypes.oledll, which uses the > > > > > > __stdcall calling convention. It's possible your DLL is defined as > > > > > > __cdecl. Try cdll.LoadLibrary instead of oledll.LoadLibrary. > > > > > > -- > > > > > > Tim Roberts, t...@probo.com > > > > > > Providenza & Boekelheide, Inc. > > > > Thanks for the reply. I've been out all last week. I'll give it a try. cdll.LoadLibrary did trick! Thanks again. Now on to the next step -- http://mail.python.org/mailman/listinfo/python-list
Re: simple client data base
> Personally, I wouldn't bother with SQLAlchemy for this. I'd just use > Python as the front end, PostgreSQL for the database, and psycopg2 > for the interface. Then you have to implement the entire logic, "event binding" etc. yourself. If you use e.g. Pypapi (the latest version), implementing an entire CRUD application is as simple as declaring your domain object model and laying out your GUI with Qt Designer. In Sqlkit, you don't have to do much more, you just don't use a designer for the GUI, but also a declarative approach. Sincerely, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
CFP: Computing, Networking and Digital Technologies
We invite participation and submissions to The International Conference on Computing, Networking and Digital Technologies (ICCNDT 2012) that will be held at Gulf University, Sanad, Bahrain from Nov. 11-13, 2012. More details can be found at the conference's official web site, visit http://sdiwc.net/bh *RESEARCH TOPICS (but not limited to): - Software Specification - Software Assurance - Social Search - Software Process Modeling - Software Reuse - Cloud Computing - Grid Computing - Green Computing - Information and Data Management *IMPORTANT DATES Paper Submission Deadline: Sept. 25, 2012 Notification of Acceptance: Oct. 10, 2012 Camera Ready Submission: Oct. 30, 2012 Registration: Oct. 30, 2012 **Please consider forwarding this message to persons who might be interested. Thank you.** -- http://mail.python.org/mailman/listinfo/python-list
sockets,threads and interupts
I have threaded python script that uses sockets to monitor network ports. I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. As I understand it signal only works in the main thread, so how can I trap interupts in my threaded class and always ensure I close the socket? Using KeyboardInterupt does not seem to work. -- http://mail.python.org/mailman/listinfo/python-list
Why derivated exception can not be pickled ?
Here is my example : import cPickle ParentClass = object # works ParentClass = Exception # does not class MyError(ParentClass): def __init__(self, arg): self.arg = arg def __getstate__(self): print '#DBG pass in getstate' odict = self.__dict__.copy() return odict def __setstate__(self, state): print '#DBG pass in setstate' self.__dict__.update(state) exc = MyError('IDMESS') fo = open('pick.1', 'w') cPickle.dump(exc, fo) fo.close() fo = open('pick.1', 'r') obj = cPickle.load(fo) fo.close() 1. With ParentClass=object, it works as expected. 2. With ParentClass=Exception, __getstate__/__setstate__ are not called. Does anyone explain me why ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 04.09.2012 04:17, Steven D'Aprano wrote: > On average, string equality needs to check half the characters in the > string. How do you arrive at that conclusion? When comparing two random strings, I just derived n = (256 / 255) * (1 - 256 ^ (-c)) where n is the average number of character comparisons and c. The rationale as follows: The first character has to be compared in any case. The second with a probability of 1/256, the third with 1/(256^2) and so on. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa -- http://mail.python.org/mailman/listinfo/python-list
Re: sockets,threads and interupts
On 04/09/2012 16:26, loial wrote: I have threaded python script that uses sockets to monitor network ports. I want to ensure that the socket is closed cleanly in all circumstances. This includes if the script is killed or interupted in some other way. As I understand it signal only works in the main thread, so how can I trap interupts in my threaded class and always ensure I close the socket? Using KeyboardInterupt does not seem to work. You could wrap it in try...finally. The 'finally' clause is guaranteed to be run, so you can close the sockets there. However, if the script is just killed, then it won't get the chance to tidy up. -- http://mail.python.org/mailman/listinfo/python-list
Error 32 - Broken Pipe . Please Help!!
Error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run already_pickled=True) File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet sock.send(struct.pack("l", len(sent_data)) + sent_data) error: [Errno 32] Broken pipe Code : #code s=1 f=0 c=0 for i in range (1,100): c=0 for j in (1,i): s+=j c=0 for k in range(1,(s/2+1)): #print s t=s%k if t==0: c+=1 if c>=5: f=1 print s break print s #code ends. The program is runnning. It has been more than 10 minutes ( currently). Should I raise my hopes for an answer ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Error 32 - Broken Pipe . Please Help!!
2012.09.04. 19:08 keltezéssel, Sreenath k írta: Error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run already_pickled=True) File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet sock.send(struct.pack("l", len(sent_data)) + sent_data) error: [Errno 32] Broken pipe Code : #code s=1 f=0 c=0 for i in range (1,100): c=0 for j in (1,i): s+=j c=0 for k in range(1,(s/2+1)): #print s t=s%k if t==0: c+=1 if c>=5: f=1 print s break print s #code ends. The program is runnning. It has been more than 10 minutes ( currently). Should I raise my hopes for an answer ? It must not be your full program. The traceback shows "Thread-1" which indicates that you are using the threading module. The other possibility is that you are feeding the output of your program into another program with a pipeline. In that case, the exception might have occured in the other program, not yours. -- http://mail.python.org/mailman/listinfo/python-list
Re: Error 32 - Broken Pipe . Please Help!!
On 9/4/2012 10:08 AM Sreenath k said... Error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 575, in run already_pickled=True) File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet sock.send(struct.pack("l", len(sent_data)) + sent_data) error: [Errno 32] Broken pipe Code : So, what code is invoking spyderlib stuff that's causing the error? Emile -- http://mail.python.org/mailman/listinfo/python-list
python docs search for 'print'
A friend made me aware of this: When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. The print statement isn't even listed as far as I can tell. Is there something that can be done about this to make it easier for beginners? I understand that this is a very basic search and "print" is a very common word and a very basic python statement, but it's pretty difficult for a beginner to learn when the first 5 results are about the disassembler and the next 5 are C functions. -Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > On 04.09.2012 04:17, Steven D'Aprano wrote: > >> On average, string equality needs to check half the characters in the >> string. > > How do you arrive at that conclusion? Take two non-empty strings of the same length, N. If the strings are equal, you have to make N comparisons to be sure they are equal (you check all N pairs of characters). If they are unequal, you have to check each pair of characters up to the first pair that are different: def string_equality(astr, bstr): # Assumes lengths are equal. for achr, bchr in zip(astr, bstr): if achr != bchr: return False return True For the unequal case, how many comparisons do you do? Ahead of time, we know very little about the strings. We don't even know how many possible characters there are (are they English alphanumeric, ASCII, Greek, Thai, or from the full range of 1114111 Unicode code points?) or what their probability distribution is. A reasonable, conservative assumption is to calculate the largest possible value of the average for random strings. That largest value occurs when the alphabet is as small as possible, namely two characters. In practice, strings come from a larger alphabet, up to 1114111 different characters for full Unicode strings, so the average for them will be less than the average we calculate now. So for unequal strings, the number of comparisons is equally likely to be 1, 2, 3, ..., N. The average then is: sum([1, 2, 3, ..., N])/N which by a bit of simple algebra works out to be (N+1)/2, or half the characters as I said. (Note that this average assumes the strings are completely random. In practice, strings tend to come from strongly non-uniform distributions of characters. For instance, in English texts, 'e' is much more likely than 'q' and most characters are vanishingly rare, and in practice, strings are likely to be highly non-random.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: sockets,threads and interupts
On 2012-09-04, MRAB wrote: > On 04/09/2012 16:26, loial wrote: >> I have threaded python script that uses sockets to monitor network >> ports. >> >> I want to ensure that the socket is closed cleanly in all >> circumstances. This includes if the script is killed or interupted in >> some other way. >> >> As I understand it signal only works in the main thread, so how can I >> trap interupts in my threaded class and always ensure I close the >> socket? Using KeyboardInterupt does not seem to work. >> > You could wrap it in try...finally. The 'finally' clause is guaranteed > to be run, so you can close the sockets there. > > However, if the script is just killed, then it won't get the chance > to tidy up. That depends on the signal used to "kill" the thread. You can catch SIGTERM and SIGINT and clean up before exiting. You can't catch SIGKILL, but sending a SIGKILL isn't considered polite unless you've already tried SIGTERM/SIGINT and it didn't work. -- Grant Edwards grant.b.edwardsYow! Are we on STRIKE yet? at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on docs.python.org, > the print function doesn't even come up in the top 20 results. > -Dave > -- > http://mail.python.org/mailman/listinfo/python-list That's pretty interesting. I always use google python and get very results. Not a correction for what you think isn't working well on python.org (I think I agree)., but if your friend is looking to learn, my suggestion works great -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on > docs.python.org, the print function doesn't even come up in the top 20 > results. The print statement isn't even listed as far as I can tell. > Is there something that can be done about this to make it easier for > beginners? > > I understand that this is a very basic search and "print" is a very > common word and a very basic python statement, but it's pretty difficult > for a beginner to learn when the first 5 results are about the > disassembler and the next 5 are C functions. If they scroll down they will find, among other entries, "1. Introduction" (to the "Python library"), which they should have read in the first place. The main problem, as I see it, is that the first search results are Unicode- sorted by document title, where uppercase letters come first. However, I do not think that posting to this newsgroup will change anything there. You should take it to the python.org people instead who are, I am sorry to say so, responsible for this mess as well¹ (I have seldom, if ever, found anything useful using that search; usually I go by TOC and index). There is a "Found a bug?" link at the bottom that appears to be of use. _ ¹ The other mess they created (or allowed to be created) is this mashup of newsgroup and mailing list, neither of which works properly, because the underlying protocols are not compatible. Add to that the abomination that Google Groups has become. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tue, 04 Sep 2012 13:58:43 -0400, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on > docs.python.org, the print function doesn't even come up in the top 20 > results. The print statement isn't even listed as far as I can tell. Is > there something that can be done about this to make it easier for > beginners? > > I understand that this is a very basic search and "print" is a very > common word and a very basic python statement, but it's pretty difficult > for a beginner to learn when the first 5 results are about the > disassembler and the next 5 are C functions. I sympathise. The search functionality on docs.python.org is frankly crap, and the best thing for your friend to do is to learn to use google, duckduckgo or some other search engine: https://www.google.com.au/search?q=python+print http://duckduckgo.com/html/?q=python+print In this case, google hits the right Python documentation on the first link. Duckduckgo doesn't do nearly so well, but it comes up with a bunch of useful third-party links. It does better for searches with fewer The second best thing for your friend to do is to learn to read the index to the docs, where the print statement is listed: http://docs.python.org/reference/index.html You can use your browser's Find command to search the page for "print". -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Sep 4, 2012, at 1:58 PM, David Hoese wrote: > A friend made me aware of this: > When a python beginner (2.x) quick searches for "print" on docs.python.org, > the print function doesn't even come up in the top 20 results. The print > statement isn't even listed as far as I can tell. Is there something that > can be done about this to make it easier for beginners? > > I understand that this is a very basic search and "print" is a very common > word and a very basic python statement, but it's pretty difficult for a > beginner to learn when the first 5 results are about the disassembler and the > next 5 are C functions. > > -Dave > -- > http://mail.python.org/mailman/listinfo/python-list +100 (or some very large number). This is a general problem in searching the python library reference ("keep this under your pillow"). Try searching for list, iter, read, or write or any one of a whole bunch of things a newbie would logically be looking for. (Or even a not-quite-newbie who wanted to check some detail.) -Bill -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tue, 04 Sep 2012 20:27:38 +0200, Thomas 'PointedEars' Lahn wrote: > ¹ The other mess they created (or allowed to be created) is this mashup >of newsgroup and mailing list, neither of which works properly, In what way do they not work properly? >because >the underlying protocols are not compatible. What? That is rather like saying that you can't read email via a web interface because the http protocol is not compatible with the smtp protocol. >Add to that the abomination that Google Groups has become. It's always been an abomination, although I understand it is much, much worse now. Blame Google for that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: focus on jtextfield
On 04.09.2012 11:34, Paolo wrote: how do I know if a JTextField has the focus? thank to all Look there: http://www.catb.org/esr/faqs/smart-questions.html#forum Bye, Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 4 September 2012 19:07, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > > > On 04.09.2012 04:17, Steven D'Aprano wrote: > > > >> On average, string equality needs to check half the characters in the > >> string. > > > > How do you arrive at that conclusion? > > Take two non-empty strings of the same length, N. If the strings are > equal, you have to make N comparisons to be sure they are equal (you > check all N pairs of characters). If they are unequal, you have to check > each pair of characters up to the first pair that are different: > > def string_equality(astr, bstr): > # Assumes lengths are equal. > for achr, bchr in zip(astr, bstr): > if achr != bchr: > return False > return True > > For the unequal case, how many comparisons do you do? Ahead of time, we > know very little about the strings. We don't even know how many possible > characters there are (are they English alphanumeric, ASCII, Greek, Thai, > or from the full range of 1114111 Unicode code points?) or what their > probability distribution is. > > A reasonable, conservative assumption is to calculate the largest > possible value of the average for random strings. That largest value > occurs when the alphabet is as small as possible, namely two characters. > In practice, strings come from a larger alphabet, up to 1114111 different > characters for full Unicode strings, so the average for them will be less > than the average we calculate now. > > So for unequal strings, the number of comparisons is equally likely to be > 1, 2, 3, ..., N. The average then is: What? > > sum([1, 2, 3, ..., N])/N > > which by a bit of simple algebra works out to be (N+1)/2, or half the > characters as I said. > > (Note that this average assumes the strings are completely random. In > practice, strings tend to come from strongly non-uniform distributions of > characters. For instance, in English texts, 'e' is much more likely than > 'q' and most characters are vanishingly rare, and in practice, strings > are likely to be highly non-random.) If the strings are 'completely random' (by which I assume you mean that each character is IID) then the probability of a match for the character at any one index is the same as the probability for a match at any other index. Lets say the probability for a match is p and that p < 1. Then for the first comparison: 1) with probability (1 - p) we terminate the loop after 1 comparison. 2) With probability p we continue to the second comparison The second comparison occurs with probability p (from 2 above) and if we reach this point then: 1) with probability (1 - p) we terminate the loop after this second comparison 2) With probability p we continue to the third comparison The probability of reaching the second comparison is p and the probability of terminating at this comparison *if we reach it* is (1-p). So the probability from the outset that we terminate at the second comparison is p*(1 - p). Prob(1 comparison) = (1-p) > p*(1-p) = prob(2 comparisons) (since p < 1) This can easily be extended by induction or otherwise to show that the probability of terminating after N comparisons decreases as N increases. In fact since it decreases by a factor of p each time, even if p is 1/2 (as would be the case if there were two equally likely characters) the probability of continuing to N comparisons becomes vanishingly small very quickly as N increases. In practise p is larger for mast ascii/bmp/unicode problems so the probability vanishes even more quickly. If you follow this through you should arrive at Johannes' result above. Applying this to real data is obviously more complicated since successive characters are not independent but it would be a fairly unusual situation if you were not more likely to stop at an earlier point in the comparison loop than a later one. Oscar. -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On 2012-09-04, Joel Goldstick wrote: > On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: >> A friend made me aware of this: >> When a python beginner (2.x) quick searches for "print" on >> docs.python.org, the print function doesn't even come up in the top >> 20 results. > > That's pretty interesting. I always use google python and > get very results. Not a correction for what you think isn't working > well on python.org (I think I agree)., but if your friend is looking > to learn, my suggestion works great googling "site:python.org " also works nicely if you know what you want is on the python.org site. I never bother with the site's search function -- the results are always far better using google. [This isn't a particular fault of the python.org site, I find the same is true for pretty much every site I've ever used.] -- Grant Edwards grant.b.edwardsYow! FROZEN ENTREES may at be flung by members of gmail.comopposing SWANSON SECTS ... -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On 9/4/2012 8:58 AM, Serhiy Storchaka wrote: On 04.09.12 04:13, Steven D'Aprano wrote: Why does the open builtin need this added complexity? Why not just call os.open directly? Or for more complex openers, just call the opener directly? What is the rationale for complicating open instead of telling people to just call their opener directly? See http://bugs.python.org/issue12797. io.open depends on a function the returns an open file descriptor. opener exposes that dependency so it can be replaced. (Obviously, one could go crazily overboard with this idea.) I believe this is a simple form of dependency injection, though it might be hard to discern from the Java-inspired verbiage of the Wikipedia article. Part of the rationale in the issue is to future-proof io.open from any future needs for alternate fd fetching. It could also be used to decouple a test of io.open from os.open -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Import Problem on WIndows py3
I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? -- http://mail.python.org/mailman/listinfo/python-list
C Python: Running Python code within function scope
The Python C API function PyEval_EvalCode let's you execute compiled Python code. I want to execute a block of Python code as if it were executing within the scope of a function, so that it has its own dictionary of local variables which don't affect the global state. This seems easy enough to do, since PyEval_EvalCode lets you provide a Global and Local dictionary: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals) The problem I run into has to do with how Python looks up variable names. Consider the following code, that I execute with PyEval_EvalCode: myvar = 300 def func(): return myvar func() This simple code actually raises an error, because Python is unable to find the variable myvar from within func. Even though myvar is in the local dictionary in the outer scope, Python doesn't copy it into the local dictionary in the inner scope. The reason for this is as follows: Whenever Python looks up a variable name, first it checks locals, then it checks globals, and finally it checks builtins. At module scope, locals and globals are the SAME dictionary object. So the statement x = 5 at module scope will place x in the the locals dictionary, which is also the globals dictionary. Now, a function defined at module scope which needs to lookup x won't find x within the function-scope locals, because Python doesn't copy module-scope locals into function-scope locals. But this normally isn't a problem, because it can find x in globals. x = 5 def foo(): print(x) # This works because 'x' in globals() == True It's only with nested functions, that Python seems to copy outer-scope locals into inner-scope locals. (It also seems to do so lazily, only if they are needed within the inner scope.) def foo(): x = 5 def bar(): print(x) # Now 'x' in locals() == True bar() So the result of all this is that, when executing code at module scope, you HAVE to make sure that your global dictionary and local dictionary are the SAME object, otherwise module-scope functions won't be able to access module-scope variables. But in my case, I don't WANT the global dictionary and local dictionary to be the same. So I need some way to tell the Python interpreter that I am executing code at function scope. Is there some way to do this? I looked at the PyCompileFlags as well as the additional arguments to PyEval_EvalCodeEx and can't find any way to do this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem on WIndows py3
On 9/4/12 9:49 AM, jimmyli1...@gmail.com wrote: I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? Do you have a (empty) __init__.py file present in this particular directory? Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem on WIndows py3
On Tuesday, September 4, 2012 1:45:55 PM UTC-7, Werner Thie wrote: > On 9/4/12 9:49 AM, jimmyli1528 wrote: > > > I have a main program and a 3rd party module. Trying to import colorama, > > where colorama is a folder with files in it, returns an ImportError: No > > module named colorama. How should I import folders? > > > > > > > > > Do you have a (empty) __init__.py file present in this particular directory? > > > > Werner OK works perfectly! -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On 04/09/2012 19:38, William R. Wing (Bill Wing) wrote: On Sep 4, 2012, at 1:58 PM, David Hoese wrote: A friend made me aware of this: When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. The print statement isn't even listed as far as I can tell. Is there something that can be done about this to make it easier for beginners? I understand that this is a very basic search and "print" is a very common word and a very basic python statement, but it's pretty difficult for a beginner to learn when the first 5 results are about the disassembler and the next 5 are C functions. -Dave -- http://mail.python.org/mailman/listinfo/python-list +100 (or some very large number). This is a general problem in searching the python library reference ("keep this under your pillow"). Try searching for list, iter, read, or write or any one of a whole bunch of things a newbie would logically be looking for. (Or even a not-quite-newbie who wanted to check some detail.) -Bill I never have a problem with this because the compiled help file on windows is awesome. It even works offline. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer wrote: > How do you arrive at that conclusion? When comparing two random strings, > I just derived > > n = (256 / 255) * (1 - 256 ^ (-c)) > > where n is the average number of character comparisons and c. The > rationale as follows: The first character has to be compared in any > case. The second with a probability of 1/256, the third with 1/(256^2) > and so on. That would be for comparing two random areas of memory. Python strings don't have 256 options per character; and in terms of actual strings, there's so many possibilities. The strings that a program is going to compare for equality are going to use a vastly restricted alphabet; for a lot of cases, there might be only a few dozen plausible characters. But even so, it's going to scale approximately linearly with the string length. If they're really random, then yes, there's little chance that either a 1MB string or a 2MB string will be the same, but with real data, they might very well have a long common prefix. So it's still going to be more or less O(n). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy wrote: > io.open depends on a function the returns an open file descriptor. opener > exposes that dependency so it can be replaced. I skimmed the bug report comments but didn't find an answer to this: Why not just monkey-patch? When a module function calls on a support function and you want to change that support function's behaviour, isn't monkey-patching the most usual? Several possibilities come to mind, but without knowledge of internals, I have no idea what's actually the case. * Patching builtins is too confusing or dangerous, and should be avoided? * You want to narrow the scope of the patch rather than do it globally? * Explicit is better than implicit? It just strikes me as something where an API change may not be necessary. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: C Python: Running Python code within function scope
On 9/4/2012 4:28 PM, channel727...@gmail.com wrote: The Python C API function PyEval_EvalCode let's you execute compiled Python code. I want to execute a block of Python code as if it were executing within the scope of a function, so that it has its own dictionary of local variables which don't affect the global state. You cannot really do this. The local namespace of functions is not a dict. This seems easy enough to do, since PyEval_EvalCode lets you provide a Global and Local dictionary: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals) When you do this, you are executing code as if in a class statement, not as if in a function. The problem I run into has to do with how Python looks up variable names. Consider the following code, that I execute with PyEval_EvalCode: myvar = 300 > def func(): return myvar func() if you wrapped this in def outer(), myvar would be a nonlocal variable, neither local nor global. exec does not allow for that. This simple code actually raises an error, because Python is unable to find the variable myvar from within func. This is the same as if you indented the above under class xxx: ... It's only with nested functions, that Python seems to copy outer-scope locals into inner-scope locals. I was surprised to find that nonlocals do appear in locals(), but I would not exactly say that they are copied into the actual local namespace. def outer(): x = 1 def inner(z=3): y = 2 print(x) print(locals()) inner() print(inner.__code__.co_varnames, inner.__code__.co_freevars) outer() # 1 {'x': 1, 'y': 2, 'z': 3} ('z', 'y') ('x',) Varnames are the local names, freevars are the nonlocal names. In any case, this complexity requires the presence of an outer function when the code is compiled. There is no way to simulate it after the fact by fiddling with just locals and globals when the compiled code is exec'ed. Class statement, on the other hand, simply introduce a local namespace separate from the module namespace. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: A friend made me aware of this: When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. In the Windows Help version of the docs, enter print in the index tab and print builtin function is at the top. Same is true of the online index. (There are only three 'print' entries. There is a duplicate for the builtin and one for the fixer. Moral: look for things that would be indexed in the index. Searching for a word in text, especially a common one like print, brings in lots of junk. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On 9/4/2012 6:32 PM, Terry Reedy wrote: On Tue, Sep 4, 2012 at 1:58 PM, David Hoese wrote: A friend made me aware of this: When a python beginner (2.x) quick searches for "print" on docs.python.org, the print function doesn't even come up in the top 20 results. In the Windows Help version of the docs, enter print in the index tab and print builtin function is at the top. Same is true of the online index. (There are only three 'print' entries. There is a duplicate for the builtin and one for the fixer. Moral: look for things that would be indexed in the index. Searching for a word in text, especially a common one like print, brings in lots of junk. Search rather blindly searches pages for words. As an experiment, I entered 'print' on the search tab of the 3.3 Windows-version doc. It found 193 pages containing 'print'. The builtin functions page was ranked 75. It is a fairly long page with just 3 occurences of 'print'. To repeat, use the index to find defining entries for Python objects. If someone wants to volunteer to write a more intelligent search algorithm, that incorporates info from the index and markup, feel free. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
How to tell people to ask questions the smart way (was: focus on jtextfield)
Andreas Perstinger writes: > On 04.09.2012 11:34, Paolo wrote: > > how do I know if a JTextField has the focus? > > thank to all > > Look there: > http://www.catb.org/esr/faqs/smart-questions.html#forum That is an unhelpful response. You aren't giving anything to help the original poster improve their question. Moreover, it is rude and dismissive, which doesn't belong in this forum. The “how to ask question the smart way” essay is not a blunt instrument for beating people over the head with, and it is brutish to use it that way. Instead, please point out *how* the original poster's question can be improved. -- \ “I think Western civilization is more enlightened precisely | `\ because we have learned how to ignore our religious leaders.” | _o__)—Bill Maher, 2003 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: The opener parameter of Python 3 open() built-in
On 9/4/2012 6:18 PM, Chris Angelico wrote: On Wed, Sep 5, 2012 at 5:16 AM, Terry Reedy wrote: io.open depends on a function the returns an open file descriptor. opener exposes that dependency so it can be replaced. I skimmed the bug report comments but didn't find an answer to this: Why not just monkey-patch? As far as I know, one can only use normal Python code to monkey patch modules written in Python. Even then, one can only rebind names stored in writable dicts -- the module dict and class attribute dicts. The attributes of function code objects are readonly. Replacing a code object is not for the faint of heart. io.py mostly loads _io compiled from C. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell people to ask questions the smart way
On 05/09/2012 00:05, Ben Finney wrote: Andreas Perstinger writes: On 04.09.2012 11:34, Paolo wrote: how do I know if a JTextField has the focus? thank to all Look there: http://www.catb.org/esr/faqs/smart-questions.html#forum That is an unhelpful response. You aren't giving anything to help the original poster improve their question. Moreover, it is rude and dismissive, which doesn't belong in this forum. The “how to ask question the smart way” essay is not a blunt instrument for beating people over the head with, and it is brutish to use it that way. Instead, please point out *how* the original poster's question can be improved. It is my opinion that the OP got exactly what they deserved, hence I entirely disagree with your response. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell people to ask questions the smart way
On Wed, Sep 5, 2012 at 9:28 AM, Mark Lawrence wrote: > On 05/09/2012 00:05, Ben Finney wrote: >> >>> Look there: >>> http://www.catb.org/esr/faqs/smart-questions.html#forum >> >> The “how to ask question the smart way” essay is not a blunt instrument >> for beating people over the head with, and it is brutish to use it that >> way. Instead, please point out *how* the original poster's question can >> be improved. > > It is my opinion that the OP got exactly what they deserved, hence I > entirely disagree with your response. There are courteous and discourteous ways to hit someone over the head with a blunt instrument. The instrument was, imho, appropriate in this instance. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 4 September 2012 22:59, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer > wrote: > > How do you arrive at that conclusion? When comparing two random strings, > > I just derived > > > > n = (256 / 255) * (1 - 256 ^ (-c)) > > > > where n is the average number of character comparisons and c. The > > rationale as follows: The first character has to be compared in any > > case. The second with a probability of 1/256, the third with 1/(256^2) > > and so on. > > That would be for comparing two random areas of memory. Python strings > don't have 256 options per character; and in terms of actual strings, > there's so many possibilities. The strings that a program is going to > compare for equality are going to use a vastly restricted alphabet; > for a lot of cases, there might be only a few dozen plausible > characters. > > But even so, it's going to scale approximately linearly with the > string length. If they're really random, then yes, there's little > chance that either a 1MB string or a 2MB string will be the same, but > with real data, they might very well have a long common prefix. So > it's still going to be more or less O(n). > It doesn't matter whether there are 256 possible characters or 2. String comparisons are best case O(1) and worst case O(n). For the average case we need to assume the distribution of the strings. Assuming random strings (with IID characters), even if there are only 2 characters the probability that all the characters up to the jth compare equal will still decrease exponentially with n, giving an average case of O(1) comparisons (if the two characters are equally likely: 1/2 + 2/4 + 3/8 + 4/16 + ... + j / (2 ** j) + ...). For real strings common prefixes may be more likely but unless the length of those common prefixes scales with n the average case number of comparisons required will not be O(n). The only way to get round the problem of O(1) string comparisons is to use strings composed entirely from a set of 1 possible character. Not only does this do away with all of the inherent performance problems of flexible string representations but it results in O(0) comparison complexity (far outstripping previous Python versions). Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell people to ask questions the smart way
Just to play advocatus diaboli, what if some seemingly simple questions are asked just to jump in and start talking python? In other words, they just wanna talk shop, no matter what it is. An OT(off topic) so to speak, and have an enlightened, and evolutionary(via brain structured acceptance of data approved for output, at the time) to discuss and get things wrong. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tue, 04 Sep 2012 18:28:31 +, Steven D'Aprano wrote: > https://www.google.com.au/search?q=python+print > http://duckduckgo.com/html/?q=python+print > > In this case, google hits the right Python documentation on the first > link. Duckduckgo doesn't do nearly so well, but it comes up with a bunch > of useful third-party links. It does better for searches with fewer Gah! Brain meltdown! DDG does better on searches for Python terms with fewer extraneous meanings, e.g. "python print" finds many links about fashion, but https://duckduckgo.com/html/?q=python+tuple is all about Python tuples :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Why derivated exception can not be pickled ?
On Tue, 04 Sep 2012 08:57:00 -0700, Mathieu Courtois wrote: > Here is my example : > > > import cPickle > > ParentClass = object # works > ParentClass = Exception # does not [...] > 1. With ParentClass=object, it works as expected. > > 2. With ParentClass=Exception, __getstate__/__setstate__ are not called. > > Does anyone explain me why ? I think it is a bug. According to the documentation, if your class is unpickleable, an exception should be raised. If it is pickleable, __getstate__ should be called. I can't see anything to explain that what you are seeing is expected behaviour. Exceptions should definitely be pickleable: http://bugs.python.org/issue1692335 so __getstate__ should be called. I think you should report this as a bug. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
Steven D'Aprano writes: > Gah! Brain meltdown! DDG does better on searches for Python terms with > fewer extraneous meanings, e.g. "python print" finds many links about > fashion, but https://duckduckgo.com/html/?q=python+tuple is all about > Python tuples :) Adding the “site:docs.python.org” term will make any DuckDuckGo search far more relevant to Python documentation. https://duckduckgo.com/?q=site%3Adocs.python.org+print> -- \ “The truth is the most valuable thing we have. Let us economize | `\ it.” —Mark Twain, _Following the Equator_ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
Roy Smith: I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. Most people write loops that go forwards. This leads to the processor designers prioritizing detection mechanisms like cache prefetching for that case. However, its not always the situation: a couple of years ago Intel contributed a memcpy implementation to glibc that went backwards for a performance improvement. An explanation from a related patch involves speculative and committed operations and address bits on some processors and quickly lost me: paragraph 3 of http://lists.freedesktop.org/archives/pixman/2010-August/000423.html The memcpy patch was controversial as it broke Adobe Flash which assumed memcpy was safe like memmove. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 05/09/2012 03:18, Neil Hodgson wrote: Roy Smith: I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. Most people write loops that go forwards. This leads to the processor designers prioritizing detection mechanisms like cache prefetching for that case. However, its not always the situation: a couple of years ago Intel contributed a memcpy implementation to glibc that went backwards for a performance improvement. An explanation from a related patch involves speculative and committed operations and address bits on some processors and quickly lost me: paragraph 3 of http://lists.freedesktop.org/archives/pixman/2010-August/000423.html The memcpy patch was controversial as it broke Adobe Flash which assumed memcpy was safe like memmove. I don't think I've ever use memcpy, only memmove. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
In article <-9cdnaqjtk6nktvnnz2dnuvz_gedn...@westnet.com.au>, Neil Hodgson wrote: > The memcpy patch was controversial as it broke Adobe Flash An added benefit! -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Tuesday, 4 September 2012 23:29:26 UTC+5:30, David Hoese wrote: > A friend made me aware of this: > > When a python beginner (2.x) quick searches for "print" on > > docs.python.org, the print function doesn't even come up in the top 20 > > results. The print statement isn't even listed as far as I can tell. > > Is there something that can be done about this to make it easier for > > beginners? > > > > I understand that this is a very basic search and "print" is a very > > common word and a very basic python statement, but it's pretty difficult > > for a beginner to learn when the first 5 results are about the > > disassembler and the next 5 are C functions. > > > > -Dave I was actually planning to write a bug on this. my project which you will *never* *never* contribute to http://code.google.com/p/py2c -- http://mail.python.org/mailman/listinfo/python-list
Re: sockets,threads and interupts
On Tuesday, 4 September 2012 23:41:13 UTC+5:30, Grant Edwards wrote: > On 2012-09-04, MRAB wrote: > > > On 04/09/2012 16:26, loial wrote: > > >> I have threaded python script that uses sockets to monitor network > > >> ports. > > >> > > >> I want to ensure that the socket is closed cleanly in all > > >> circumstances. This includes if the script is killed or interupted in > > >> some other way. > > >> > > >> As I understand it signal only works in the main thread, so how can I > > >> trap interupts in my threaded class and always ensure I close the > > >> socket? Using KeyboardInterupt does not seem to work. > > >> > > > You could wrap it in try...finally. The 'finally' clause is guaranteed > > > to be run, so you can close the sockets there. > > > > > > However, if the script is just killed, then it won't get the chance > > > to tidy up. > > > > That depends on the signal used to "kill" the thread. > > > > You can catch SIGTERM and SIGINT and clean up before exiting. > > > > You can't catch SIGKILL, but sending a SIGKILL isn't considered polite > > unless you've already tried SIGTERM/SIGINT and it didn't work. > > > > -- > > Grant Edwards grant.b.edwardsYow! Are we on STRIKE yet? > > at > > gmail.com We could just use a "with" statement. Neater, easier. -- http://mail.python.org/mailman/listinfo/python-list
Re: Error 32 - Broken Pipe . Please Help!!
On Tuesday, 4 September 2012 22:38:03 UTC+5:30, Sreenath k wrote: > Error: > > > > > > Exception in thread Thread-1: > > Traceback (most recent call last): > > File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner > > self.run() > > File > "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", > line 575, in run > > already_pickled=True) > > File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line > 24, in write_packet > > sock.send(struct.pack("l", len(sent_data)) + sent_data) > > error: [Errno 32] Broken pipe > > > > Code : > > > > #code > > > > s=1 > > f=0 > > c=0 > > > > for i in range (1,100): > > c=0 > > for j in (1,i): > > s+=j > > c=0 > > for k in range(1,(s/2+1)): > > #print s > > t=s%k > > if t==0: > > c+=1 > > if c>=5: > > f=1 > > print s > > break > > > > print s > > > > #code ends. > > > > The program is runnning. It has been more than 10 minutes ( currently). > Should I raise my hopes for an answer ? *Please* make your variable names more descriptive. -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
The generated code can be run without Python installed and does not embed Python. For example: print("Hello World to py2c!") would be translated to #include "iostream" using namespace std; //If you want you can make py2c not add this and use std::cout instead of cout int main() { cout<<"Hello World to py2c!\n"; return 0; } Python is written in C, or so I'm told. So why don't you just look at the interpreter section/built-ins for the function of print? A good command line tutorial in C/C++ could show how python is handled through the terminal with a cin << print value; cout >> 'value', printf, etc. But I believe the original question is why is it not listed further up, maybe it's going alphabetically. -- Something like Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Zooming and Editing TkInter Images
How do I zoom in on a tkinter image? And how do I change the selected pixel to a changeable color when the user clicks or drags? -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On 9/4/2012 11:22 PM, Ramchandra Apte wrote: I was actually planning to write a bug on this. If you do, find the right place to submit it. bugs.python.org is for issues relating to the cpython repository.' I fairly sure that the website search code is not there. If you do find the right place, you should contribute something to an improvement. The current search performance is not a secret, so mere complaints are useless. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell people to ask questions the smart way
On Sep 5, 4:27 am, Mark Lawrence wrote: > On 05/09/2012 00:05, Ben Finney wrote: > > > > > > > > > > > Andreas Perstinger writes: > > >> On 04.09.2012 11:34, Paolo wrote: > >>> how do I know if a JTextField has the focus? > >>> thank to all > > >> Look there: > >>http://www.catb.org/esr/faqs/smart-questions.html#forum > > > That is an unhelpful response. You aren't giving anything to help the > > original poster improve their question. Moreover, it is rude and > > dismissive, which doesn't belong in this forum. > > > The “how to ask question the smart way” essay is not a blunt instrument > > for beating people over the head with, and it is brutish to use it that > > way. Instead, please point out *how* the original poster's question can > > be improved. > > It is my opinion that the OP got exactly what they deserved, hence I > entirely disagree with your response. As a impartial response to what is 'deserved' it is fine. However... If we did not make these dicta as a norm - return unkindness with less unkindness (said in strange terms of cheeks and coats etc) - Do unto others as you would have them etc we would be back in the jungle. In the context of mailing lists/fora hopefully one needs to distinguish new post-ers/members from habitual idiots? And if all this sounds over-Christian see http://en.wikipedia.org/wiki/Robustness_principle Or more in line with python principles, the dilemma http://chrismdp.github.com/2012/02/on-coding-defensively/ -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs search for 'print'
On Wednesday, 5 September 2012 09:35:43 UTC+5:30, Terry Reedy wrote: > On 9/4/2012 11:22 PM, Ramchandra Apte wrote: > > > > > I was actually planning to write a bug on this. > > > > If you do, find the right place to submit it. > > bugs.python.org is for issues relating to the cpython repository.' > > I fairly sure that the website search code is not there. > > > > If you do find the right place, you should contribute something to an > > improvement. The current search performance is not a secret, so mere > > complaints are useless. > > > > -- > > Terry Jan Reedy I was thinking we could just use Google Site search (it's fast easy to setup and gives good results) -- http://mail.python.org/mailman/listinfo/python-list
Re: sockets,threads and interupts
loial writes: > I have threaded python script that uses sockets to monitor network ports. > > I want to ensure that the socket is closed cleanly in all circumstances. This > includes if the script is killed or interupted in some other way. The operating system should close all sockets automatically when the process dies. Thus, if closing alone is sufficient... -- http://mail.python.org/mailman/listinfo/python-list
Re: Why derivated exception can not be pickled ?
Mathieu Courtois writes: > Here is my example : > > > import cPickle > > ParentClass = object # works > ParentClass = Exception # does not > > class MyError(ParentClass): > def __init__(self, arg): > self.arg = arg > > def __getstate__(self): > print '#DBG pass in getstate' > odict = self.__dict__.copy() > return odict > > def __setstate__(self, state): > print '#DBG pass in setstate' > self.__dict__.update(state) > > exc = MyError('IDMESS') > > fo = open('pick.1', 'w') > cPickle.dump(exc, fo) > fo.close() > > fo = open('pick.1', 'r') > obj = cPickle.load(fo) > fo.close() > > > 1. With ParentClass=object, it works as expected. > > 2. With ParentClass=Exception, __getstate__/__setstate__ are not called. The pickle interface is actually more complex and there are several ways an object can ensure picklability. For example, there is also a "__reduce__" method. I suppose, that "Exception" defines methods which trigger the use of an alternative picklability approach (different from "__getstate__/__setstate__"). I would approach your case the following way: Use "pickle" instead of "cPickle" and debug picking/unpickling to find out what happens in detail. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginners question
Hi, I have attached python interview questions and answers for beginners. Please visit http://www.f2finterview.com/web/CorePython/ for core python and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python On Thursday, August 30, 2012 5:24:08 PM UTC+5:30, (unknown) wrote: > Hello > > > > I'm slowly teaching myself python so apologies if this is a dumb question. > > but something has confused me with the os.stat() function: > > > > >>> s = os.stat(".") > > >>> print s > > posix.stat_result(st_mode=16877, st_ino=2278764L, st_dev=2053L, st_nlink=2, > st_u > > id=1000, st_gid=100, st_size=4096L, st_atime=1346327745, st_mtime=1346327754, > st > > _ctime=1346327754) > > > > What sort of object is posix.stat_result? Its not a dictionary or list or a > > class object as far as I can tell. Thanks for any help. > > > > B2003 -- http://mail.python.org/mailman/listinfo/python-list
why did the WindowsError occur?
my code: import os os.startfile(r'C:\Program Files\Internet Explorer.exe') the error: os.startfile(r'C:\Program Files\Internet Explorer.exe') WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' -- http://mail.python.org/mailman/listinfo/python-list
is implemented with id ?
Hi ! a is b <==> id(a) == id(b) in builtin classes. Is that true ? Thanks, franck -- http://mail.python.org/mailman/listinfo/python-list
Re: is implemented with id ?
On Tue, Sep 4, 2012 at 11:30 PM, Franck Ditter wrote: > Hi ! > a is b <==> id(a) == id(b) in builtin classes. > Is that true ? > Thanks, > > franck No. It is true that if a is b then id(a) == id(b) but the reverse is not necessarily true. id is only guaranteed to be unique among objects alive at the same time. If objects are discarded, their ids may be reused even though the objects are not the same. -- http://mail.python.org/mailman/listinfo/python-list
[Ann] superfixer - stop hardcoding class names in super calls
Hi All, I have a small library which supplies a metaclass superfixer, which when applied to a class, provides every method with a variable __class__, which refers to the class in which the method is defined. This avoids the need to refer to the current class name in calls to super. If there's any interest, it could be extended to provide a no-args form of super. All suggestions and enhancements gratefully accepted! https://github.com/marcintustin/superfixer -- Marcin Tustin -- http://mail.python.org/mailman/listinfo/python-list
Re: why did the WindowsError occur?
On Tue, Sep 4, 2012 at 11:30 PM, Levi Nie wrote: > my code: > import os > os.startfile(r'C:\Program Files\Internet Explorer.exe') > > the error: > os.startfile(r'C:\Program Files\Internet Explorer.exe') > WindowsError: [Error 2] : 'C:\\Program Files\\Internet Explorer.exe' > There's no such thing as C:\Program Files\Internet Explorer.exe. You probably want C:\Program Files\Internet Explorer\iexplore.exe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Hi Guys, Finally I have decided to put best interview question and answers. Please visit http://www.f2finterview.com/web/CorePython/ for core python and http://www.f2finterview.com/web/PythonAdvanced/ for advanced python On Tuesday, October 30, 2007 11:44:01 PM UTC+5:30, Krypto wrote: > Hi, > > I have used Python for a couple of projects last year and I found it > extremely useful. I could write two middle size projects in 2-3 months > (part time). Right now I am a bit rusty and trying to catch up again > with Python. > > I am now appearing for Job Interviews these days and I am wondering if > anybody of you appeared for a Python Interview. Can you please share > the questions you were asked. That will be great help to me. > > Thanks, -- http://mail.python.org/mailman/listinfo/python-list