The Python Tutorial, in Spanish
Hi all! We finally translated to Spanish the very last version of the Python Tutorial! You can grab it here in PDF [0], or see it online here [1]. Furthermore, we printed it [2]! It was a giveaway in PyCon Argentina 2009, :D Regards, [0] http://python.org.ar/pyar/Tutorial [1] http://docs.python.org.ar/tutorial/contenido.html [2] http://www.taniquetil.com.ar/facundo/imgs/tutorialimpreso.jpg -- .Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: Hypy 0.8.4
Hypy is a fulltext search interface for Python applications. Use it to index and search your documents from Python code. Hypy is based on the estraiernative bindings by Yusuke Yoshida. * Fast, scalable * Perfect recall ratio by N-gram method * High precision by hybrid mechanism of N-gram and morphological analyzer * Phrase search, regular expressions, attribute search (including numeric and date comparisons), and similarity search * Simple and powerful API Homepage, downloads, everything, etc.: http://goonmill.org/hypy/ This is of course on pypi and can be installed with easy_install. You will need Hyper Estraier installed to use it. Release Version 0.8.4 (2009.09.19) ~~ Bugfix release. * It is now possible to construct an attribute-only search with None for search phrase. All known bugs are now fixed. -- _ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: pyjamas pyv8run converts python to javascript, executes under command-line
John Nagle wrote: Daniel Fetchinson wrote: Barring the unimplemented libraries and bugs, yes. If you read the original post in this thread, you will see that on the roadmap is running the entire Python regression suite. No, it's getting close to running the entire Pyjamas regression suite, which is something else. I was referring to this statement: on the roadmap of this sub-sub-project of pyjamas is: * to throw pyv8run at the standard http://python.org regression tests and see what sticks -- 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: Can print() be reloaded for a user defined class?
r rt8...@gmail.com wrote in message news:c87c1742-e185-4377-a3ae-b32b912bc...@33g2000vbe.googlegroups.com... On Sep 19, 9:53 pm, Peng Yu pengyu...@gmail.com wrote: (snip) I want to understand the exact meaning of the last line ('__repr__ = __str__'). Would you please point me to the section of the python manual that describes such usage. simple i assined any call to __repr__ to the __str__ methods. Just define __repr__. str() uses __repr__ if __str__ isn't defined. -Mark -- http://mail.python.org/mailman/listinfo/python-list
Compile kinterbasdb with mingw32 and python 2.6 - DLL load failed
This is what I did so far: #1. Install Python 2.6, Firebird 1.5 server (with libs and headers), egenix mx base and mingw C compiler #2. put c:\MinGW\bin on the PATH (or wherever it is) #3. extract kinterbasdb source to a temp folder #4. hack setup.cfg. Change the build section: [build] compiler=mingw32 #5. hack setup.py Replace this: customCompilerName = 'msvc' With this: customCompilerName = 'mingw32-gcc' #6. run python setup.py install The building and installation went find. But I cannot import kinterbasdb because I get a DLL load failed error. I figured out that has something to do with msvcr90 and _ftime. Can you please give me some advice how to solve this problem? Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: How to change string or number passed as argument?
On Sunday 20 September 2009 03:59:21 Peng Yu wrote: I know that strings or numbers are immutable when they passed as arguments to functions. But there are cases that I may want to change them in a function and propagate the effects outside the function. I could wrap them in a class, which I feel a little bit tedious. I am wondering what is the common practice for this problem. You can just ignore the immutability. Nothing stops you doing something like this; def reader(port,buffer): buffer += port.read() return buffer and calling it repetitively until buffer is as long as you want it. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
Peng Yu wrote: snip def __str__(self): return 'Bin(%s, %s)' %(self.x, self.y) __repr__ =_str__ Please use an initial capital letter when defining a class, this is the accepted way in many languages!!! I want to understand the exact meaning of the last line ('__repr__ __str__'). Would you please point me to the section of the python manual that describes such usage. Regards, Peng I don't know where to look in the various manuals, but what we have here are class attributes. Inside the class definition, each method definition is a class attribute. In addition, any variable definition is a class attribute as well. For example, class MyClass(object): counter = 0 def __str__(self): return Kilroy+str(self.value) def __init__(self, num): self.value = num+1 counter is a class attribute, initialized to zero. That attribute is shared among all the instances, unlike data attributes, which are independently stored in each instance. Anyway, the __repr__ = __str__ simply copies a class attribute. So now you have two names which call the same method. To explicitly call one of them, you might use: obj = MyClass(42) mystring = obj.__str__()#mystring is now Kilroy43 But normally, you don't directly call such methods, except for debug purposes. They are implicitly called by functions like print(). -- http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
Hendrik van Rooyen wrote: Yikes! If I follow you, it is a bit like having a hollow dumb-bell with a hollow handle of zero length, and wanting a word for that opening between the knobs. That's pretty much it, yes. Although opening doesn't quite cut it, because there can be two of them sharing an edge with no physical substance in between, yet they are two distinct entities rather than a single opening. I do not think that you are likely to find a word in *any* language for that Probably not in any everyday language, no. It's a fairly abstract concept. But programming has a way of taking abstract concepts and turning them into concrete ones. I had this object in my data structure, and I needed a name for it. In any case, it doesn't affect my point, which was that I was thinking about something that I didn't have a word, or even a convenient phrase for. That is probably true, but on the other hand, it is not totally rubbish either, as it is hard to think of stuff you have never heard of, whether you have an undefined word for it or not. I quite agree that there is *some* interaction between the language we use and the way we think, but it's a two-way process. As a species, we're quite capable of thinking about new things and inventing words to express them when the need arises. It's possible that some individuals do this more frequently than others, e.g. mathematicians and other people who are in the habit of exploring new ideas may be less influenced by the constraints of language than the general population. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
Jiang Fung Wong wrote: Dear All, Thank you for the information. I think I've some idea what the problem is about after seeing the replies. More information about my system and my script PIII 1Ghz, 512MB RAM, Windows XP SP3 The script monitors global input using PyHook, and calculates on the information collected from the events to output some numbers. Based on the numbers, the script then performs some automation using SendKeys module. here is the memory usage: firefox.exe, 69MB, 109MB svchost.exe, 26MB, 17MB pythonw.exe, 22MB, 17MB searchindexer.exe, 16MB, 19MB My first guess is that the script calculated for too long time after receiving an event before propagating it to the default handler, resulting the system to be non-responsive. I will try to implement the calculation part in another thread. Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour. (You top-posted this message, putting the whole stream out of order. So I deleted the history.) All my assumptions about your environment are now invalid. You don't have a CPU-bound application, you have a Windows application with event loop. Further, you're using SendKeys to generate a keystroke to the other process. So there are many things that could be affecting your latency, and all my previous guesses are useless. Adding threads to your application will probably slow the system down much more. You need to find out what your present problem is before complicating it. You haven't really described the problem. You say the system is unresponsive, but you made it that way by creating a global hook; a notoriously inefficient mechanism. That global hook inserts code into every process in the system, and you've got a pretty low-end environment to begin with. So what's the real problem, and how severe is it? And how will you measure improvement? The Task manager numbers are probably irrelevant. My first question is whether the pyHook event is calling the SendKeys function directly (after your lengthy calculation) or whether there are other events firing off in between. If it's all being done in the one event, then measure its time, and gather some statistics (min time, max time, average...). The task manager has far too simplistic visibility to be useful for this purpose. What else is this application doing when it's waiting for a pyHook call? Whose event loop implementation are you using? And the program you're trying to control -- is there perhaps another way in? DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: What are the naming convention for private member variable, and private and public member function?
Peng Yu wrote: Hi, It says in http://www.python.org/dev/peps/pep-0008/ Method Names and Instance Variables Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability. Use one leading underscore only for non-public methods and instance variables. I am wondering what is the different between member function and member variable in term of naming convention. Regards, Peng Member functions are verbs or sometimes adjectives, while member variables are nouns. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sep 19, 9:34 pm, Peng Yu pengyu...@gmail.com wrote: On Sep 19, 6:05 pm, Robert Kern robert.k...@gmail.com wrote: http://nedbatchelder.com/text/python-parsers.html This is more a less just a list of parsers. I would like some detailed guidelines on which one to choose for various parsing problems. it would be simpler if you described what you want to do - parsers can be used for a lot of problems. also, the parsers do not exist in isolation - you need to worry about whether they are supported, how good the documentation is, etc. and different parsers handle different grammars - see http://wiki.python.org/moin/LanguageParsing - so if you already have a particular grammar then your life is simpler if you choose a parser that matches. these are the three that i know most about - i think all three are currently maintained: for simple parsing problems, i think pyparsing is the most commonly used - http://pyparsing.wikispaces.com/ my own lepl - http://www.acooke.org/lepl/ - tries to combine ease of use with some more advanced features the nltk - http://www.nltk.org/ - is particularly targeted at parsing natural languages and includes a wide variety of tools. but for parsing a large project you might be better interfacing to a compiled parser (lepl has memoisation, so should scale quite well, but it's not something i've looked at in detail yet). andrew -- http://mail.python.org/mailman/listinfo/python-list
Pickle Encoding Errors
To demonstrate the problem I have written the following program: ___ Code Start import pickle destruct=1 class PickleTest: library={} def __init__(self): self.unpickle() def __del__(self): if destruct: print Pickling from destructor... self.pickle() def unpickle(self): try: f=open(pickle.txt) self.library=pickle.load(f) f.close() print Unpickled just fine except: print Error unpickling self.library={uA: 1, uB: 2, uC: 3} def pickle(self): f=open(pickle.txt,w) pickle.dump(self.library,f) f.close() print Pickled just fine if __name__==__main__: pt=PickleTest() if not destruct: print Pickling from __main__... pt.pickle() ___ Code End Running the program with pickle.txt not created and destruct=1 generates the following output: Error unpickling Pickling from destructor... Exception exceptions.LookupError: 'unknown encoding: raw-unicode- escape' in bound method PickleTest.__del__ of __main__.PickleTest instance at 0xb7d3decc ignored If I now change destruct to 0 the output is: Error unpickling Pickling from __main__... Pickled just fine Even more odd is that with an existing pickle.txt and destruct set to 1 it seems to work correctly: Unpickled just fine Pickling from destructor... Pickled just fine I'm running Python 2.5.4 on Debian Sid. If anybody understands the error please enlighten me. Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
On Sun, Sep 20, 2009 at 4:42 AM, Dave Angel da...@ieee.org wrote: Peng Yu wrote: snip def __str__(self): return 'Bin(%s, %s)' %(self.x, self.y) __repr__ =_str__ Please use an initial capital letter when defining a class, this is the accepted way in many languages!!! I want to understand the exact meaning of the last line ('__repr__ __str__'). Would you please point me to the section of the python manual that describes such usage. Regards, Peng I don't know where to look in the various manuals, but what we have here are class attributes. Inside the class definition, each method definition is a class attribute. In addition, any variable definition is a class attribute as well. For example, class MyClass(object): counter = 0 def __str__(self): return Kilroy+str(self.value) def __init__(self, num): self.value = num+1 counter is a class attribute, initialized to zero. That attribute is shared among all the instances, unlike data attributes, which are independently stored in each instance. Anyway, the __repr__ = __str__ simply copies a class attribute. So now you have two names which call the same method. To explicitly call one of them, you might use: Is __repr__ = __str__ copy by reference or by value? If I change __str__ later on, will __repr__ be changed automatically? Regards, Peng obj = MyClass(42) mystring = obj.__str__() #mystring is now Kilroy43 But normally, you don't directly call such methods, except for debug purposes. They are implicitly called by functions like print(). -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sun, Sep 20, 2009 at 6:50 AM, andrew cooke and...@acooke.org wrote: On Sep 19, 9:34 pm, Peng Yu pengyu...@gmail.com wrote: On Sep 19, 6:05 pm, Robert Kern robert.k...@gmail.com wrote: http://nedbatchelder.com/text/python-parsers.html This is more a less just a list of parsers. I would like some detailed guidelines on which one to choose for various parsing problems. it would be simpler if you described what you want to do - parsers can be used for a lot of problems. I have never used any parser. The task at my hand right now is to parse this http://genome.ucsc.edu/goldenPath/help/wiggle.html, which is a fairly simple even without any parser package. I think that it is worthwhile for me to learn some parser packages to try to parse this format. So that I may in future parse more complex syntax. Do you have any suggestion what parser I should use for now? Regards, Peng also, the parsers do not exist in isolation - you need to worry about whether they are supported, how good the documentation is, etc. and different parsers handle different grammars - see http://wiki.python.org/moin/LanguageParsing - so if you already have a particular grammar then your life is simpler if you choose a parser that matches. these are the three that i know most about - i think all three are currently maintained: for simple parsing problems, i think pyparsing is the most commonly used - http://pyparsing.wikispaces.com/ my own lepl - http://www.acooke.org/lepl/ - tries to combine ease of use with some more advanced features the nltk - http://www.nltk.org/ - is particularly targeted at parsing natural languages and includes a wide variety of tools. but for parsing a large project you might be better interfacing to a compiled parser (lepl has memoisation, so should scale quite well, but it's not something i've looked at in detail yet). andrew -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
Peng Yu pengyu...@gmail.com wrote: Is __repr__ = __str__ copy by reference or by value? If I change __str__ later on, will __repr__ be changed automatically? What would you expect the outcome to be if these were functions rather than class methods? (Or any type of object, really...) Wouldn't it be quicker (and certainly less spammy) to test this out in the interpreter? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the minimum number that can be represented?
On Sun, Sep 20, 2009 at 12:46 AM, Daniel Fetchinson fetchin...@googlemail.com wrote: Suppose I want to define a function that return the minimum number that can be represented. def f(x): #body That it, if I call f(10), f will return the minimum integer that can be represented in the machine; if I cal f(10.5), f will return the minimum float that can be represented in the machine. Could somebody let me know what should be in the function body? I'm not sure this is what you are looking for but have a look at import sys print sys.maxint The problem is how to know what type of the argument and call the corresponding function. In C++, it is relatively easy (limits header). Is there an equivalent in python? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sep 20, 8:11 am, Peng Yu pengyu...@gmail.com wrote: On Sun, Sep 20, 2009 at 6:50 AM, andrew cooke and...@acooke.org wrote: On Sep 19, 9:34 pm, Peng Yu pengyu...@gmail.com wrote: On Sep 19, 6:05 pm, Robert Kern robert.k...@gmail.com wrote: http://nedbatchelder.com/text/python-parsers.html This is more a less just a list of parsers. I would like some detailed guidelines on which one to choose for various parsing problems. it would be simpler if you described what you want to do - parsers can be used for a lot of problems. I have never used any parser. The task at my hand right now is to parse thishttp://genome.ucsc.edu/goldenPath/help/wiggle.html, which is a fairly simple even without any parser package. I think that it is worthwhile for me to learn some parser packages to try to parse this format. So that I may in future parse more complex syntax. Do you have any suggestion what parser I should use for now? pyparsing would work fine for that, and has a broad community of users that will probably be helpful. i am currently working on an extension to lepl that is related, and i may use that format as an example. if so, i'll tell you. but for now, i think pyparsing makes more sense for you. andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickle Encoding Errors
I'm running Python 2.5.4 on Debian Sid. If anybody understands the error please enlighten me. Very interesting! Here is a minimalist version: import pickle class PickleTest: def __init__(self): self.library={uA: 1,uB: 2,uC: 3} def __del__(self): self.pickle() def pickle(self): pickle.dumps(self.library) pt=PickleTest() However, the exception is not thrown if dictionary keys are not unicodes. cPickle version is even more strange: import cPickle class PickleTest: def __init__(self): self.library={uA: 1,uB: 2,uC: 3} def __del__(self): self.pickle() def pickle(self): cPickle.dumps(self.library) pt=PickleTest() Result: Exception AttributeError: 'NoneType' object has no attribute 'dumps' in bound method PickleTest.__del__ of __main__.PickleTest instance at 0x00CC1F08 ignored Of course the error is gone if you do this: if __name__ == __main__: pt=PickleTest() del pt # No more references to object, will be destroyed before the main program starts exiting. You should NOT write files from object destructors anyway. You can never know when an object willl be destroyed. The correct way to implement this is to put it in try - finally pt=PickleTest() try: do_something_with(pt) finally: pt.pickle() Best. Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sep 19, 11:39 pm, TerryP bigboss1...@gmail.com wrote: [...] For flat data, simple unix style rc or dos style ini file will often suffice, and writing a parser is fairly trivial; in fact writing a [...] python already includes parsers for .ini configuration files. [...] The best way to choose a parser, is experiment with several, test (and profile!) them according to the project, then pick the one you like best, out of those that are suitable for the task. Profiling can be very important. profiling is going to show you the constant complexity, but - unless you think hard - it's not going to explain how a parser will scale (how performance changes as the amount of text to be parsed increases). for that, you need to look at the algorithm used, which is usually documented somewhere. there's going to be trade-offs - parsers that handle large texts better could well be more complex and slower on small texts. andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickle Encoding Errors
Dan wrote: Error unpickling Pickling from destructor... Exception exceptions.LookupError: 'unknown encoding: raw-unicode- escape' in bound method PickleTest.__del__ of __main__.PickleTest instance at 0xb7d3decc ignored If I now change destruct to 0 the output is: Error unpickling Pickling from __main__... Pickled just fine Even more odd is that with an existing pickle.txt and destruct set to 1 it seems to work correctly: Unpickled just fine Pickling from destructor... Pickled just fine I'm running Python 2.5.4 on Debian Sid. If anybody understands the error please enlighten me. __del__ is called in an indeterministic order. Most of the Python environment is already gone when your __del__ method is called. The pickle module doesn't have enough bits left to fulfill its job. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame and py2app : big package
TerryP bigboss1...@gmail.com wrote: I used py2app on Mac to build a package of my game (using pygame). It works fine (better than py2exe, i can'tmake work at tht time). But the package is very big. The biggest thing is numpy lib : 19 MB ! numpy is very big and i doubt all is reallly needed Excuse me, but what was the point? (id est, are you just saying this or do you wish to ask a question?;) Sorry, it was not clear. But i want to know if i can make the package smaller, because the total package weight 59.4 MB just for a small arcade game. -- Pierre-Alain Dorange MicroWar 2.0 : tuez des PC http://microwar.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickle Encoding Errors
On 20 Sep, 13:29, Christian Heimes li...@cheimes.de wrote: Dan wrote: Error unpickling Pickling from destructor... Exception exceptions.LookupError: 'unknown encoding: raw-unicode- escape' in bound method PickleTest.__del__ of __main__.PickleTest instance at 0xb7d3decc ignored If I now change destruct to 0 the output is: Error unpickling Pickling from __main__... Pickled just fine Even more odd is that with an existing pickle.txt and destruct set to 1 it seems to work correctly: Unpickled just fine Pickling from destructor... Pickled just fine I'm running Python 2.5.4 on Debian Sid. If anybody understands the error please enlighten me. __del__ is called in an indeterministic order. Most of the Python environment is already gone when your __del__ method is called. The pickle module doesn't have enough bits left to fulfill its job. Christian Thank you both for your advice. Python is very new to me so still plenty to learn. I still think it's interesting that once the file exists there is no error generated but at least I know how it should be done. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
One word of warning - the documentation for that format says at the beginning that it is compressed in some way. I am not sure if that means within some program, or on disk. But most parsers will not be much use with a compressed file - you will need to uncompress it first. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sun, Sep 20, 2009 at 7:20 AM, andrew cooke and...@acooke.org wrote: On Sep 20, 8:11 am, Peng Yu pengyu...@gmail.com wrote: On Sun, Sep 20, 2009 at 6:50 AM, andrew cooke and...@acooke.org wrote: On Sep 19, 9:34 pm, Peng Yu pengyu...@gmail.com wrote: On Sep 19, 6:05 pm, Robert Kern robert.k...@gmail.com wrote: http://nedbatchelder.com/text/python-parsers.html This is more a less just a list of parsers. I would like some detailed guidelines on which one to choose for various parsing problems. it would be simpler if you described what you want to do - parsers can be used for a lot of problems. I have never used any parser. The task at my hand right now is to parse thishttp://genome.ucsc.edu/goldenPath/help/wiggle.html, which is a fairly simple even without any parser package. I think that it is worthwhile for me to learn some parser packages to try to parse this format. So that I may in future parse more complex syntax. Do you have any suggestion what parser I should use for now? pyparsing would work fine for that, and has a broad community of users that will probably be helpful. i am currently working on an extension to lepl that is related, and i may use that format as an example. if so, i'll tell you. but for now, i think pyparsing makes more sense for you. The file size of a wig file can be very large (GB). Most tasks on this file format does not need the parser to save all the lines read from the file in the memory to produce the parsing result. I'm wondering if pyparsing is capable of parsing large wig files by keeping only minimum required information in the memory. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the minimum number that can be represented?
On Sep 20, 1:15 pm, Peng Yu pengyu...@gmail.com wrote: The problem is how to know what type of the argument and call the corresponding function. type(1) type 'int' type(1.2) type 'float' -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
On Sep 20, 6:24 pm, Dave Angel da...@ieee.org wrote: Jiang Fung Wong wrote: Dear All, Thank you for the information. I think I've some idea what the problem is about after seeing the replies. More information about my system and my script PIII 1Ghz, 512MB RAM, Windows XP SP3 The script monitors global input using PyHook, and calculates on the information collected from the events to output some numbers. Based on the numbers, the script then performs some automation using SendKeys module. here is the memory usage: firefox.exe, 69MB, 109MB svchost.exe, 26MB, 17MB pythonw.exe, 22MB, 17MB searchindexer.exe, 16MB, 19MB My first guess is that the script calculated for too long time after receiving an event before propagating it to the default handler, resulting the system to be non-responsive. I will try to implement the calculation part in another thread. Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour. (You top-posted this message, putting the whole stream out of order. So I deleted the history.) All my assumptions about your environment are now invalid. You don't have a CPU-bound application, you have a Windows application with event loop. Further, you're using SendKeys to generate a keystroke to the other process. So there are many things that could be affecting your latency, and all my previous guesses are useless. Adding threads to your application will probably slow the system down much more. You need to find out what your present problem is before complicating it. You haven't really described the problem. You say the system is unresponsive, but you made it that way by creating a global hook; a notoriously inefficient mechanism. That global hook inserts code into every process in the system, and you've got a pretty low-end environment to begin with. So what's the real problem, and how severe is it? And how will you measure improvement? The Task manager numbers are probably irrelevant. My first question is whether the pyHook event is calling the SendKeys function directly (after your lengthy calculation) or whether there are other events firing off in between. If it's all being done in the one event, then measure its time, and gather some statistics (min time, max time, average...). The task manager has far too simplistic visibility to be useful for this purpose. What else is this application doing when it's waiting for a pyHook call? Whose event loop implementation are you using? And the program you're trying to control -- is there perhaps another way in? DaveA Hi, Sorry I wasn't sure how to use Google groups to post a msg to the newsgroup, I used Gmail to write my previous reply. What you and the other guy have provided me isn't useless. Now I understand the non- responsiveness may not be caused by high CPU usage, as the OS, be it Windows or Linux, has a way to prioritize the tasks. This is a vital clue to me. By not responsive, I mean, for some time, the mouse pointer is not moving smoothly, to such extent that I can't do anything with the mouse. It's like playing a multi-player game on a connection with a lot of lag. It's not caused by global hook, because it happens under certain condition, i.e. when fpa.ProcessEvent(word) is computing. I included my main script for your reference. Comments: (1) The automation method tc.Auto() is slow, but it doesn't cause any problem, because the user would wait for the automation to finish, before he continues to do something. (2) all other methods invoked are fast, except fpa.ProcessEvent(word) (this information is obtained from profiling). It is this method that causes 100% CPU usage. I'm planning to move this method to a separate thread, so that OnEvent(event) can finish executing, while the separate thread goes on to finish its calculation. Is this a good idea? import pyHook import TypingAnalyzer import GUI def OnEvent(event): if hasattr(event, Key) and event.Ascii == 9 and event.Key == Tab and event.Injected == 0 and event.Alt == 0: tc.Auto() return False else: recognized = rk.ProcessEvent(event) if recognized: tc.MatchChar(recognized) paragraph = rc.ProcessEvent(recognized) if paragraph: for word in paragraph: fpa.ProcessEvent(word) return True hm = pyHook.HookManager() hm.MouseAllButtonsDown = OnEvent hm.KeyDown = OnEvent hm.HookMouse() hm.HookKeyboard() rk = TypingAnalyzer.ReadKey() rc = TypingAnalyzer.ReadChar() fpa = TypingAnalyzer.Analysis() tc = TypingAnalyzer.Automation(fpa) if __name__ == '__main__': app = GUI.AWAApp() app.MainLoop() Thank you for your attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
The file size of a wig file can be very large (GB). Most tasks on this file format does not need the parser to save all the lines read from the file in the memory to produce the parsing result. I'm wondering if pyparsing is capable of parsing large wig files by keeping only minimum required information in the memory. ok, now you are getting into the kind of detail where you will need to ask the authors of individual packages. lepl is stream oriented and should behave as you want (it will only keep in memory what it needs, and will read data gradually from a file) but (1) it's fairly new and i have not tested the memory use - there may be some unexpected memory leak; (2) it's python 2.6/3 only; (3) parsing line-based formats like this is not yet supported very well (you can do it, but you have to explicitly match the newline character to find the end of line); (4) the community for support is small. so i would suggest asking on the pyparsing list for advice on using that with large data files (you are getting closer to the point where i would recommend lepl - but of course i am biased as i wrote it). andrew ps is there somewhere can download example files? this would be useful for my own testing. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
also, parsing large files may be slow. in which case you may be better with a non-python solution (even if you call it from python). your file format is so simple that you may find a lexer is enough for what you want, and they should be stream oriented. have a look at the shlex package that is already in python. will that help? alternatively, perhaps plex - http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/ - that is pure python, but greg ewing is a good programmer and he says on that page it is as fast as possible for python, so it is probably going to be quite fast. andrew ps maybe you already know, but a lexer is simpler than a parser in that it doesn't use the context to decide how to treat things. so it can recognise something is a number, or a word, or a quoted string, but not whether it is part of a track definition line or a data value, for example. but in this case the format is so simple that a lexer might do quite a ot of what you want, and would make the remaining plain python program very simple. -- http://mail.python.org/mailman/listinfo/python-list
Re: Compile kinterbasdb with mingw32 and python 2.6 - DLL load failed
On Mon, Sep 21, 2009 at 12:23 AM, Laszlo Nagy gand...@shopzeus.com wrote: This is what I did so far: #1. Install Python 2.6, Firebird 1.5 server (with libs and headers), egenix mx base and mingw C compiler #2. put c:\MinGW\bin on the PATH (or wherever it is) #3. extract kinterbasdb source to a temp folder #4. hack setup.cfg. Change the build section: [build] compiler=mingw32 #5. hack setup.py Replace this: customCompilerName = 'msvc' With this: customCompilerName = 'mingw32-gcc' #6. run python setup.py install The building and installation went find. But I cannot import kinterbasdb because I get a DLL load failed error. I figured out that has something to do with msvcr90 and _ftime. Can you please give me some advice how to solve this problem? Download Microsoft Visual C++.2008 Express Edition -- http://mail.python.org/mailman/listinfo/python-list
List comprehension vs generator expression memory allocation
Let's code a function allowing access to the multiples of a given integer (say m) in the range from a to b where a and b are two given integers. For instance, with data input a,b,m=17, 42, 5 the function allows access to : 20 25 30 35 40 Each of the following two functions mult1() and mult2() solves the question : # - def mult1(a,b,m): return (x for x in range(a,b)[(m-a%m)%m:b:m]) def mult2(a,b,m): return range(a,b)[(m-a%m)%m:b:m] # - mult2() function returns a list and obviously mult2() needs Python to allocate memory for this list. What I was wondering is if the same might be said about mult1(). More precisely, does Python allocate memory for the whole target list range(a,b)[m-a%m:b:m]? -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sun, Sep 20, 2009 at 8:19 AM, andrew cooke and...@acooke.org wrote: also, parsing large files may be slow. in which case you may be better with a non-python solution (even if you call it from python). your file format is so simple that you may find a lexer is enough for what you want, and they should be stream oriented. have a look at the shlex package that is already in python. will that help? alternatively, perhaps plex - http://www.cosc.canterbury.ac.nz/greg.ewing/python/Plex/ - that is pure python, but greg ewing is a good programmer and he says on that page it is as fast as possible for python, so it is probably going to be quite fast. andrew ps maybe you already know, but a lexer is simpler than a parser in that it doesn't use the context to decide how to treat things. so it can recognise something is a number, or a word, or a quoted string, but not whether it is part of a track definition line or a data value, for example. but in this case the format is so simple that a lexer might do quite a ot of what you want, and would make the remaining plain python program very simple. I don't quite understand this point. If I don't use a parser, since python can read numbers line by line, why I need a lexer package? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
I don't quite understand this point. If I don't use a parser, since python can read numbers line by line, why I need a lexer package? for the lines of numbers it would make no difference; for the track definition lines it would save you some work. as you said, this is a simple format, so the case for any tool is marginal - i'm just exploring the options. andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension vs generator expression memory allocation
On 20 Sep, 14:35, candide cand...@free.invalid wrote: Let's code a function allowing access to the multiples of a given integer (say m) in the range from a to b where a and b are two given integers. For instance, with data input a,b,m=17, 42, 5 the function allows access to : 20 25 30 35 40 Each of the following two functions mult1() and mult2() solves the question : # - def mult1(a,b,m): return (x for x in range(a,b)[(m-a%m)%m:b:m]) def mult2(a,b,m): return range(a,b)[(m-a%m)%m:b:m] # - mult2() function returns a list and obviously mult2() needs Python to allocate memory for this list. What I was wondering is if the same might be said about mult1(). More precisely, does Python allocate memory for the whole target list range(a,b)[m-a%m:b:m]? Yes - range always creates a list (in the 2.x series) -- mult1 creates a list, then returns a generator, so list(mult1(a,b,m)) is identical to mult2(a,b,m). Jon. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sun, Sep 20, 2009 at 8:49 AM, andrew cooke and...@acooke.org wrote: I don't quite understand this point. If I don't use a parser, since python can read numbers line by line, why I need a lexer package? for the lines of numbers it would make no difference; for the track definition lines it would save you some work. So for the track definition, using a lexer package would be better than using regex in python, right? as you said, this is a simple format, so the case for any tool is marginal - i'm just exploring the options. andrew -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Can print() be reloaded for a user defined class?
Peng Yu wrote: snip you might use: Is __repr__ =_str__ copy by reference or by value? If I change __str__ later on, will __repr__ be changed automatically? Regards, Peng Reference or value? Neither one. This assignment is no different than any other attribute assignment in Python. Technically, it binds the name __repr__ to the function object already bound by __str__. You now have a second name pointing to the same object. Rebinding one of those names to yet another different object won't affect the other name. name1 = this is a test name2 = name1 name1 = another string #this has no effect on name2 print name1, name2 DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
So for the track definition, using a lexer package would be better than using regex in python, right? they are similar. a lexer is really just a library that packages regular expressions in a certain way. so you could write your own code and you would really be writing a simple lexer. the advantage of writing your own code is that it will be easier to modify and you will get more experience with regular expressions. the advantage of using a library (a lexer) is that it has already been tested by other people, it is already packaged and so your code will be better structured, and it may have features (perhaps logging, or handling of quoted strings, for example) that will save you some work in the future. andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the minimum number that can be represented?
On 2009-09-20, Peng Yu pengyu...@gmail.com wrote: Suppose I want to define a function that return the minimum number that can be represented. def f(x): #body That it, if I call f(10), f will return the minimum integer that can be represented in the machine; if I cal f(10.5), f will return the minimum float that can be represented in the machine. Could somebody let me know what should be in the function body? The stuff you wan is in the sys module. For example: sys.float_info sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1) sys.maxint 2147483647 You might also want to read up on the type() builtin -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
kakarukeys wrote: On Sep 20, 6:24 pm, Dave Angel da...@ieee.org wrote: Jiang Fung Wong wrote: Dear All, Thank you for the information. I think I've some idea what the problem is about after seeing the replies. More information about my system and my script PIII 1Ghz, 512MB RAM, Windows XP SP3 The script monitors global input using PyHook, and calculates on the information collected from the events to output some numbers. Based on the numbers, the script then performs some automation using SendKeys module. here is the memory usage: firefox.exe, 69MB, 109MB svchost.exe, 26MB, 17MB pythonw.exe, 22MB, 17MB searchindexer.exe, 16MB, 19MB My first guess is that the script calculated for too long time after receiving an event before propagating it to the default handler, resulting the system to be non-responsive. I will try to implement the calculation part in another thread. Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour. (You top-posted this message, putting the whole stream out of order. So I deleted the history.) All my assumptions about your environment are now invalid. You don't have a CPU-bound application, you have a Windows application with event loop. Further, you're using SendKeys to generate a keystroke to the other process. So there are many things that could be affecting your latency, and all my previous guesses are useless. Adding threads to your application will probably slow the system down much more. You need to find out what your present problem is before complicating it. You haven't really described the problem. You say the system is unresponsive, but you made it that way by creating a global hook; a notoriously inefficient mechanism. That global hook inserts code into every process in the system, and you've got a pretty low-end environment to begin with. So what's the real problem, and how severe is it? And how will you measure improvement? The Task manager numbers are probably irrelevant. My first question is whether the pyHook event is calling the SendKeys function directly (after your lengthy calculation) or whether there are other events firing off in between. If it's all being done in the one event, then measure its time, and gather some statistics (min time, max time, average...). The task manager has far too simplistic visibility to be useful for this purpose. What else is this application doing when it's waiting for a pyHook call? Whose event loop implementation are you using? And the program you're trying to control -- is there perhaps another way in? DaveA Hi, Sorry I wasn't sure how to use Google groups to post a msg to the newsgroup, I used Gmail to write my previous reply. What you and the other guy have provided me isn't useless. Now I understand the non- responsiveness may not be caused by high CPU usage, as the OS, be it Windows or Linux, has a way to prioritize the tasks. This is a vital clue to me. By not responsive, I mean, for some time, the mouse pointer is not moving smoothly, to such extent that I can't do anything with the mouse. It's like playing a multi-player game on a connection with a lot of lag. It's not caused by global hook, because it happens under certain condition, i.e. when fpa.ProcessEvent(word) is computing. I included my main script for your reference. Comments: (1) The automation method tc.Auto() is slow, but it doesn't cause any problem, because the user would wait for the automation to finish, before he continues to do something. (2) all other methods invoked are fast, except fpa.ProcessEvent(word) (this information is obtained from profiling). It is this method that causes 100% CPU usage. I'm planning to move this method to a separate thread, so that OnEvent(event) can finish executing, while the separate thread goes on to finish its calculation. Is this a good idea? import pyHook import TypingAnalyzer import GUI def OnEvent(event): if hasattr(event, Key) and event.Ascii == 9 and event.Key == Tab and event.Injected == 0 and event.Alt == 0: tc.Auto() return False else: recognized = rk.ProcessEvent(event) if recognized: tc.MatchChar(recognized) paragraph = rc.ProcessEvent(recognized) if paragraph: for word in paragraph: fpa.ProcessEvent(word) return True hm = pyHook.HookManager() hm.MouseAllButtonsDown = OnEvent hm.KeyDown = OnEvent hm.HookMouse() hm.HookKeyboard() rk = TypingAnalyzer.ReadKey() rc = TypingAnalyzer.ReadChar() fpa = TypingAnalyzer.Analysis() tc = TypingAnalyzer.Automation(fpa) if __name__ == '__main__': app = GUI.AWAApp() app.MainLoop() Thank you for your attention. I can't readily comment on your code, since it's entirely
Re: Re: Can print() be reloaded for a user defined class?
On Sun, Sep 20, 2009 at 9:19 AM, Dave Angel da...@ieee.org wrote: Peng Yu wrote: snip you might use: Is __repr__ =_str__ copy by reference or by value? If I change __str__ later on, will __repr__ be changed automatically? Regards, Peng Reference or value? Neither one. This assignment is no different than any other attribute assignment in Python. Technically, it binds the name __repr__ to the function object already bound by __str__. You now have a second name pointing to the same object. Rebinding one of those names to yet another different object won't affect the other name. name1 = this is a test name2 = name1 name1 = another string #this has no effect on name2 print name1, name2 I am more familiar with C++ than python. So I need to connect python concept to C++ concept so that I can understand it better. name1 and name are all references (in the C++ sense), right? __repr__ and __str__ are references (in the C++ sense) to functions and both of them could refer to the same function or two different ones, right? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
How python source code in large projects are organized?
Hi, I am wondering what is the best way of organizing python source code in a large projects. There are package code, testing code. I'm wondering if there has been any summary on previous practices. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the minimum number that can be represented?
On Sun, Sep 20, 2009 at 9:37 AM, Grant Edwards inva...@invalid.invalid wrote: On 2009-09-20, Peng Yu pengyu...@gmail.com wrote: Suppose I want to define a function that return the minimum number that can be represented. def f(x): #body That it, if I call f(10), f will return the minimum integer that can be represented in the machine; if I cal f(10.5), f will return the minimum float that can be represented in the machine. Could somebody let me know what should be in the function body? The stuff you wan is in the sys module. For example: sys.float_info sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1) sys.maxint 2147483647 You might also want to read up on the type() builtin I want avoid using any 'if' statement. In C++, I can use template. How to do not use 'if' statement in python? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension vs generator expression memory allocation
Jon Clements wrote: On 20 Sep, 14:35, candide cand...@free.invalid wrote: Let's code a function allowing access to the multiples of a given integer (say m) in the range from a to b where a and b are two given integers. For instance, with data input a,b,m, 42, 5 the function allows access to : 20 25 30 35 40 Each of the following two functions mult1() and mult2() solves the question : # - def mult1(a,b,m): return (x for x in range(a,b)[(m-a%m)%m:b:m]) def mult2(a,b,m): return range(a,b)[(m-a%m)%m:b:m] # - mult2() function returns a list and obviously mult2() needs Python to allocate memory for this list. What I was wondering is if the same might be said about mult1(). More precisely, does Python allocate memory for the whole target list range(a,b)[m-a%m:b:m]? Yes - range always creates a list (in the 2.x series) -- mult1 creates a list, then returns a generator, so list(mult1(a,b,m)) is identical to mult2(a,b,m). Jon. First, you're clearly using python 2.x, since in version 3, you'd get an error in each of the definitions, doing the slice on a generator. Both of those functions create the identical list (after first creating a bigger one!). Then mult1() creates a generator object that owns the list, and passes back the generator object. The list isn't freed till the calling code releases the generator object. The code in mult2() just passes the list back directly, and it'll get freed when the calling code stops using it (eg. reuses the attribute which references it). So mult1() adds extra complexity without saving any memory. If you want to save memory, try (not thoroughly tested): def mult3(a, b, m): start = m*((a-1)/m + 1) end = m*((b-1)/m + 1) return xrange(start, end, m) -- http://mail.python.org/mailman/listinfo/python-list
How to refer to class name and function name in a python program?
Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __repr__(self): return 'In A::__repr__' a = A() print a -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
On Sep 20, 10:16 am, Peng Yu pengyu...@gmail.com wrote: (snip) I am more familiar with C++ than python. So I need to connect python concept to C++ concept so that I can understand it better. name1 and name are all references (in the C++ sense), right? __repr__ and __str__ are references (in the C++ sense) to functions and both of them could refer to the same function or two different ones, right? Don't ever try and map C++ to Python on a 1:1 basis or you will get quite confused. Try this thought experiment, and remember, the Python shell is your best friend now! IDLE 2.6.2 a = 1 b = 1 a 1 b 1 id(a) 27822424 id(b) 27822424 help(id) Help on built-in function id in module __builtin__: id(...) id(object) - integer Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (Hint: it's the object's memory address.) NOW you can apply that logic 1:1 to your python problem ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame and py2app : big package
Pierre-Alain Dorange wrote: Sorry, it was not clear. But i want to know if i can make the package smaller, because the total package weight 59.4 MB just for a small arcade game. You would need to skip or strip out any unneeded components that are being packed. Either by playing with how py2app sucks them up (I don't use py2app) or by post processing the file it produces in order to remove them. (I'm not familiar with OSX beyond the unix portions.) On my laptop, the entire standard libraries .py/.pyc/.pyo files is about 54M. -- http://mail.python.org/mailman/listinfo/python-list
Re: An assessment of the Unicode standard
2009/9/19 r rt8...@gmail.com: Snap (sort of). Does anybody know where the concept of the purple people eater comes from? I mean is there a children's book or something? - Hendrik I've always assumed it to go back to the 1958 Sheb Wooley song. Which I remember, although I was only 3 when it was released. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to class name and function name in a python program?
On Sep 20, 10:38 am, Peng Yu pengyu...@gmail.com wrote: Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __repr__(self): return 'In A::__repr__' a = A() print a well thats easy ;-) return 'A, __repr__' was that too easy? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to class name and function name in a python program?
Peng Yu pengyu...@gmail.com wrote: Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __repr__(self): return 'In A::__repr__' a = A() print a def __repr__(self): return 'In %s::__repr__' % self.__class__.__name__ You already know the function is called __repr__ so you don't need to look it up anywhere. If you really wanted to do it the hard way: import inspect ... def __repr__(self): return 'In %s::%s' % (self.__class__.__name__, inspect.getframeinfo(inspect.currentframe()).function) but just repeating __repr__ explicitly is less typing. -- http://mail.python.org/mailman/listinfo/python-list
I look for proxy cache like apt-pro xy (for Debian Package) but for python eggs package…
Hi, I look for a tools to do proxy cache like apt-proxy (for Debian Package) but for python eggs package. Can a easy-install option perform this feature ? Thanks for your help, Stephane -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
On Sep 20, 10:57 pm, Dave Angel da...@ieee.org wrote: kakarukeys wrote: On Sep 20, 6:24 pm, Dave Angel da...@ieee.org wrote: Jiang Fung Wong wrote: Dear All, Thank you for the information. I think I've some idea what the problem is about after seeing the replies. More information about my system and my script PIII 1Ghz, 512MB RAM, Windows XP SP3 The script monitors global input using PyHook, and calculates on the information collected from the events to output some numbers. Based on the numbers, the script then performs some automation using SendKeys module. here is the memory usage: firefox.exe, 69MB, 109MB svchost.exe, 26MB, 17MB pythonw.exe, 22MB, 17MB searchindexer.exe, 16MB, 19MB My first guess is that the script calculated for too long time after receiving an event before propagating it to the default handler, resulting the system to be non-responsive. I will try to implement the calculation part in another thread. Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour. (You top-posted this message, putting the whole stream out of order. So I deleted the history.) All my assumptions about your environment are now invalid. You don't have a CPU-bound application, you have a Windows application with event loop. Further, you're using SendKeys to generate a keystroke to the other process. So there are many things that could be affecting your latency, and all my previous guesses are useless. Adding threads to your application will probably slow the system down much more. You need to find out what your present problem is before complicating it. You haven't really described the problem. You say the system is unresponsive, but you made it that way by creating a global hook; a notoriously inefficient mechanism. That global hook inserts code into every process in the system, and you've got a pretty low-end environment to begin with. So what's the real problem, and how severe is it? And how will you measure improvement? The Task manager numbers are probably irrelevant. My first question is whether the pyHook event is calling the SendKeys function directly (after your lengthy calculation) or whether there are other events firing off in between. If it's all being done in the one event, then measure its time, and gather some statistics (min time, max time, average...). The task manager has far too simplistic visibility to be useful for this purpose. What else is this application doing when it's waiting for a pyHook call? Whose event loop implementation are you using? And the program you're trying to control -- is there perhaps another way in? DaveA Hi, Sorry I wasn't sure how to use Google groups to post a msg to the newsgroup, I used Gmail to write my previous reply. What you and the other guy have provided me isn't useless. Now I understand the non- responsiveness may not be caused by high CPU usage, as the OS, be it Windows or Linux, has a way to prioritize the tasks. This is a vital clue to me. By not responsive, I mean, for some time, the mouse pointer is not moving smoothly, to such extent that I can't do anything with the mouse. It's like playing a multi-player game on a connection with a lot of lag. It's not caused by global hook, because it happens under certain condition, i.e. when fpa.ProcessEvent(word) is computing. I included my main script for your reference. Comments: (1) The automation method tc.Auto() is slow, but it doesn't cause any problem, because the user would wait for the automation to finish, before he continues to do something. (2) all other methods invoked are fast, except fpa.ProcessEvent(word) (this information is obtained from profiling). It is this method that causes 100% CPU usage. I'm planning to move this method to a separate thread, so that OnEvent(event) can finish executing, while the separate thread goes on to finish its calculation. Is this a good idea? import pyHook import TypingAnalyzer import GUI def OnEvent(event): if hasattr(event, Key) and event.Ascii == 9 and event.Key == Tab and event.Injected == 0 and event.Alt == 0: tc.Auto() return False else: recognized = rk.ProcessEvent(event) if recognized: tc.MatchChar(recognized) paragraph = rc.ProcessEvent(recognized) if paragraph: for word in paragraph: fpa.ProcessEvent(word) return True hm = pyHook.HookManager() hm.MouseAllButtonsDown = OnEvent hm.KeyDown = OnEvent hm.HookMouse() hm.HookKeyboard() rk = TypingAnalyzer.ReadKey() rc = TypingAnalyzer.ReadChar() fpa = TypingAnalyzer.Analysis() tc = TypingAnalyzer.Automation(fpa) if __name__ == '__main__': app =
Re: How to refer to class name and function name in a python program?
On Sep 20, 8:38 pm, Peng Yu pengyu...@gmail.com wrote: Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __repr__(self): return 'In A::__repr__' a = A() print a Using decorator: def echo(func): def _echo(self, *args, **kw): return In %s.%s % (self.__class__.__name__, func.func_name) return _echo class A: @echo def __repr__(self): pass a = A() print a -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to class name and function name in a python program?
On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte vijayendra.ba...@gmail.com wrote: On Sep 20, 8:38 pm, Peng Yu pengyu...@gmail.com wrote: Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __repr__(self): return 'In A::__repr__' a = A() print a Using decorator: def echo(func): def _echo(self, *args, **kw): return In %s.%s % (self.__class__.__name__, func.func_name) return _echo class A: �...@echo def __repr__(self): pass a = A() print a What does @echo mean? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to class name and function name in a python program?
On Sep 20, 10:38 am, Peng Yu pengyu...@gmail.com wrote: Hi, I have the following code. I want to change the function body of __repr__ to something like PS: Methods get angry when you refer to them as functions . You see, methods feel that they are more than a mere lowly function, and have developed a superiority complex about it. And you would not want to get them upset either -- since they have friends in high places (classes) and can really put a hurt on you. ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Can print() be reloaded for a user defined class?
On Sun, Sep 20, 2009 at 11:16 AM, Peng Yu pengyu...@gmail.com wrote: On Sun, Sep 20, 2009 at 9:19 AM, Dave Angel da...@ieee.org wrote: Peng Yu wrote: snip you might use: Is __repr__ =_str__ copy by reference or by value? If I change __str__ later on, will __repr__ be changed automatically? Regards, Peng Reference or value? Neither one. This assignment is no different than any other attribute assignment in Python. Technically, it binds the name __repr__ to the function object already bound by __str__. You now have a second name pointing to the same object. Rebinding one of those names to yet another different object won't affect the other name. name1 = this is a test name2 = name1 name1 = another string #this has no effect on name2 print name1, name2 I am more familiar with C++ than python. So I need to connect python concept to C++ concept so that I can understand it better. name1 and name are all references (in the C++ sense), right? __repr__ and __str__ are references (in the C++ sense) to functions and both of them could refer to the same function or two different ones, right? Sort of, but it would be best to forget about the C++ ideas of references and values because it will only confuse you. In python, everything is an object and every attribute is stored as a dict key, including functions. When you do __repr__ = __str__, you are making the name '__repr__' refer to the same object as the name '__str__'. Since they are the same object, any mutations made to one object will appear in the other. However, a reassignment does not change the value of the object, it just makes that key refer to another object. So if you were to later change __str__ to a different method, __repr__ wouldn't change. Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to class name and function name in a python program?
On Sun, Sep 20, 2009 at 12:43 PM, Peng Yu pengyu...@gmail.com wrote: On Sun, Sep 20, 2009 at 11:32 AM, Vijayendra Bapte vijayendra.ba...@gmail.com wrote: On Sep 20, 8:38 pm, Peng Yu pengyu...@gmail.com wrote: Hi, I have the following code. I want to change the function body of __repr__ to something like return 'In %s::%s' % ($class_name, $function_name) I'm wondering what I should write for $class_name and $function_name in python. Regards, Peng class A: def __init__(self): pass def __repr__(self): return 'In A::__repr__' a = A() print a Using decorator: def echo(func): def _echo(self, *args, **kw): return In %s.%s % (self.__class__.__name__, func.func_name) return _echo class A: �...@echo def __repr__(self): pass a = A() print a What does @echo mean? Regards, Peng It's a decorator, which wraps the function with another function it's the equivalent of calling def __repr__(self) : pass __repr__ = echo(__repr__) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get the minimum number that can be represented?
On 2009-09-20, Peng Yu pengyu...@gmail.com wrote: You might also want to read up on the type() builtin I want avoid using any 'if' statement. Why? In C++, I can use template. If you want to write C++ code, then you should use a C++ compiler. How to do not use 'if' statement in python? In python you use the 'if' statement. -- Grant Edwards grante Yow! I am covered with at pure vegetable oil and I am visi.comwriting a best seller! -- http://mail.python.org/mailman/listinfo/python-list
Re: How python source code in large projects are organized?
I am wondering what is the best way of organizing python source code in a large projects. There are package code, testing code. I'm wondering if there has been any summary on previous practices. I suggest looking at the source code of large projects like twisted, PIL, django, turbogears, etc. These have different styles, pick the one you like best. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
Peng Yu wrote: The file size of a wig file can be very large (GB). Most tasks on this file format does not need the parser to save all the lines read from the file in the memory to produce the parsing result. I'm wondering if pyparsing is capable of parsing large wig files by keeping only minimum required information in the memory. I cannot recommend pyparsing for large amounts of text. Even before you hit memory limits, you will run into the problem that pyparsing runs many functions for each character of text. Python function calls are expensive. Since the format is line-oriented, one option is to use pyparsing or other parser to handle the track definition lines and just str.split(), float() and int() for the data lines. -- 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
Python/MySQL Frustration
Hi; I have the following code: while i num: cat = 'cat' + str(i) cat = form.getfirst(cat, '') item = 'item' + str(i) item = form.getfirst(item, '') descr = 'descr' + str(i) descr = form.getfirst(descr, '') uom = 'uom' + str(i) uom = form.getfirst(uom, '') price = 'price' + str(i) price = form.getfirst(price, '') sql = 'Category=' + cat + ', Item=' + item + ', Description=' + descr + ', UOM=' + uom + ', Price=' + price + '' sql = 'insert into %s values (%s);' % (company, sql) cursor.execute(sql) i += 1 Now, all of this posts to the mysql database, but it forms an infinite loop! I have num == 1! I have printed num to make sure it's actually only 1 (or 2, depending). What in the heck am I doing wrong? TIA, Victor -- http://mail.python.org/mailman/listinfo/python-list
Re: I look for proxy cache like apt-proxy (for Debian Package) but for python eggs package…
Klein Stéphane schrieb: Hi, I look for a tools to do proxy cache like apt-proxy (for Debian Package) but for python eggs package. Can a easy-install option perform this feature ? No. But you might install EggBasket, which is a PyPI-like server. http://www.chrisarndt.de/projects/eggbasket/ However, it is *not* a proxy, and to the best of my knowledge that's not easily done anyway due to the way easy_install is working. It scrapes the website it is pointed to, and when it finds something it likes, follows that. Thus the server doesn't get an idea *what* easy_install is looking for, and thus can't relay the request to the real PyPI, fetching the egg, storing it locally, and then re-deliver it. Instead what we do with eggbasket is to copy all the eggs we obtained by other means into a central repository that he serves. Thus we have them backed-up available even if PyPI or the actual package go away. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/MySQL Frustration
On Sep 20, 2009, at 2:25 PM, Victor Subervi wrote: Hi; I have the following code: while i num: cat = 'cat' + str(i) cat = form.getfirst(cat, '') item = 'item' + str(i) item = form.getfirst(item, '') descr = 'descr' + str(i) descr = form.getfirst(descr, '') uom = 'uom' + str(i) uom = form.getfirst(uom, '') price = 'price' + str(i) price = form.getfirst(price, '') sql = 'Category=' + cat + ', Item=' + item + ', Description=' + descr + ', UOM=' + uom + ', Price=' + price + '' sql = 'insert into %s values (%s);' % (company, sql) cursor.execute(sql) i += 1 Now, all of this posts to the mysql database, but it forms an infinite loop! I have num == 1! I have printed num to make sure it's actually only 1 (or 2, depending). What in the heck am I doing wrong? Are you sure that num is a integer and not a string? What happens when you step through the code with a debugger? Simplify your code, for your sake and ours. Begin commenting out lines, starting with cursor.execute(sql) and working your way up to the first line below the while statement. (You can replace the cursor.execute() with a print statement to monitor the value of i.) Does your infinite loop disappear when you get rid of that stuff? HTH Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sep 20, 9:12 am, andrew cooke and...@acooke.org wrote: ps is there somewhere can download example files? this would be useful for my own testing. thanks. i replied to a lot of your questions here; any chance you could reply to this one of mine? the wig format looks like it could be a good test for lepl. thanks, andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: How python source code in large projects are organized?
On Sun, Sep 20, 2009 at 11:31 AM, Daniel Fetchinson fetchin...@googlemail.com wrote: I am wondering what is the best way of organizing python source code in a large projects. There are package code, testing code. I'm wondering if there has been any summary on previous practices. I suggest looking at the source code of large projects like twisted, PIL, django, turbogears, etc. These have different styles, pick the one you like best. Is there a webpage or a document that describes various practices? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)
On Sep 19, 9:22 pm, Schif Schaf schifsc...@gmail.com wrote: The other day I needed to convert a date like August 2009 into a seconds-since-epoch value (this would be for the first day of that month, at the first second of that day). In Python, I came up with this: #!/usr/bin/env python import datetime import time time_in_sse = time.mktime( datetime.datetime(2009, 8, 1).timetuple() ) (datetime.datetime(2009, 8, 1) - datetime.datetime(1970, 1, 1)).days * 86400 But still, this should be part of the datetime class. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sun, Sep 20, 2009 at 1:35 PM, andrew cooke and...@acooke.org wrote: On Sep 20, 9:12 am, andrew cooke and...@acooke.org wrote: ps is there somewhere can download example files? this would be useful for my own testing. thanks. i replied to a lot of your questions here; any chance you could reply to this one of mine? the wig format looks like it could be a good test for lepl. I missed your question. I have only some files that I only use a subset of the syntax in wig. Here is one example. track type=wiggle_0 name=MACS_counts_after_shifting description=H3K4me1B variableStep chrom=chr10 span=10 3001871 1 3001881 1 3001891 1 3001901 1 track type=wiggle_0 name=MACS_counts_after_shifting description=H3K4me1B variableStep chrom=chr11 span=10 3000331 3 3000341 3 3000351 3 3000361 3 3000371 3 3000381 3 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/MySQL Frustration
Yeah, that was the problem...num was a string ;) Just caught it myself, too. Thanks, V On Sun, Sep 20, 2009 at 2:37 PM, Philip Semanchuk phi...@semanchuk.comwrote: On Sep 20, 2009, at 2:25 PM, Victor Subervi wrote: Hi; I have the following code: while i num: cat = 'cat' + str(i) cat = form.getfirst(cat, '') item = 'item' + str(i) item = form.getfirst(item, '') descr = 'descr' + str(i) descr = form.getfirst(descr, '') uom = 'uom' + str(i) uom = form.getfirst(uom, '') price = 'price' + str(i) price = form.getfirst(price, '') sql = 'Category=' + cat + ', Item=' + item + ', Description=' + descr + ', UOM=' + uom + ', Price=' + price + '' sql = 'insert into %s values (%s);' % (company, sql) cursor.execute(sql) i += 1 Now, all of this posts to the mysql database, but it forms an infinite loop! I have num == 1! I have printed num to make sure it's actually only 1 (or 2, depending). What in the heck am I doing wrong? Are you sure that num is a integer and not a string? What happens when you step through the code with a debugger? Simplify your code, for your sake and ours. Begin commenting out lines, starting with cursor.execute(sql) and working your way up to the first line below the while statement. (You can replace the cursor.execute() with a print statement to monitor the value of i.) Does your infinite loop disappear when you get rid of that stuff? HTH Philip -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
SQLObject 0.10.7
Hello! I'm pleased to announce version 0.10.7, a minor bugfix release of 0.10 branch of SQLObject. What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.10.7 News and changes: http://sqlobject.org/News.html What's New == News since 0.10.6 - * Fixed a bug: Sybase tables with identity column fire two identity_inserts. * Fixed a bug: q.startswith(), q.contains() and q.endswith() escape (with a backslash) all special characters (backslashes, underscores and percent signs). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytmannhttp://phd.pp.ru/p...@phd.pp.ru Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: How python source code in large projects are organized?
On 07:10 pm, pengyu...@gmail.com wrote: On Sun, Sep 20, 2009 at 11:31 AM, Daniel Fetchinson fetchin...@googlemail.com wrote: I am wondering what is the best way of organizing python source code in a large projects. There are package code, testing code. I'm wondering if there has been any summary on previous practices. I suggest looking at the source code of large projects like twisted, PIL, django, turbogears, etc. These have different styles, pick the one you like best. Is there a webpage or a document that describes various practices? I wrote very briefly on this topic, hope it helps: http://jcalderone.livejournal.com/39794.html Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
easy question, how to double a variable
Write the definition of a function twice , that receives an int parameter and returns an int that is twice the value of the parameter. how can i do this -- http://mail.python.org/mailman/listinfo/python-list
Re: Granularity of OSError
On Sep 19, 9:22 pm, MRAB pyt...@mrabarnett.plus.com wrote: The point is that it's sometimes a good idea to do a cheap check first before attempting an operation that's 'expensive' even when it fails. Strongly agree. Furthermore, with LBYL it's often easier to give a user clearer error messages for common usage errors, rather than waiting for an exception in a much lower-level place where it's less clear to them what the cause is. -- http://mail.python.org/mailman/listinfo/python-list
Name 'NewAxis' is not defined
I found such a script - a gas model. http://des.memphis.edu/lurbano/vpython/gas/Temp_KE_07.py Can anybody help and find a mistake. There is a message: Name 'NewAxis' is not defined. I tried Python 25 with numpy 121 and Python 26 with scipy 071. (Win Vista). -- mo (not proffessional programmer ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Name 'NewAxis' is not defined
mo wrote: I found such a script - a gas model. http://des.memphis.edu/lurbano/vpython/gas/Temp_KE_07.py Can anybody help and find a mistake. There is a message: Name 'NewAxis' is not defined. I tried Python 25 with numpy 121 and Python 26 with scipy 071. (Win Vista). This file was written expecting that VPython would be using Numeric, numpy's predecessor, and exposing its symbols. Numeric.NewAxis == numpy.newaxis. -- 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: easy question, how to double a variable
daggerdvm wrote: Write the definition of a function twice , that receives an int parameter and returns an int that is twice the value of the parameter. how can i do this That's a very basic question. Try a tutorial. -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
daggerdvm wrote: Write the definition of a function twice , that receives an int parameter and returns an int that is twice the value of the parameter. how can i do this Read over your textbook and the notes you took in class -- I'm sure therein you'll find how to define functions, how to specify parameters, how to return values, and how to do basic arithmetic operations. You can also hit up python.org and diveintopython.org for more reading if you need. I'll give you a hint: If you use twice = lambda x: int(x**2/(0.5*x)) I suspect your professor will flunk you for cheating. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Name 'NewAxis' is not defined
mo wrote: I found such a script - a gas model. http://des.memphis.edu/lurbano/vpython/gas/Temp_KE_07.py Can anybody help and find a mistake. There is a message: Name 'NewAxis' is not defined. I tried Python 25 with numpy 121 and Python 26 with scipy 071. (Win Vista). I can't see a definition for NewAxis. Is it defined in one of the module's you import, 'visual' or 'visual.graph'? -- http://mail.python.org/mailman/listinfo/python-list
Re: on package import, have it conditionally import a subpackage
On Sep 19, 4:06 pm, Gabriel Rossetti gabriel.rosse...@arimaz.com wrote: Hello everyone, I'd like to ba able to import a package and have it's __init__ conditionally import a subpackage. Suppose that you have this structure : mybase/ mybase/__init__.py mybase/mypkg mybase/mypkg/__init__.py mybase/mypkg/module0.py mybase/mypkg/type1 mybase/mypkg/type1/__init__.py mybase/mypkg/type1/module1.py mybase/mypkg/type1/module2.py mybase/mypkg/type2 mybase/ mypkg/type2/__init__.py mybase/ mypkg/type2/module1.py mybase/ mypkg/type2/module2.py I'd like to do something like th following in my code import mybase mybase.setType(type1) from mybase.mypkg import module0, module1, module2 module0.__file__ 'mybase/mypkg/module0.pyc' module1.__file__ 'mybase/mypkg/type1/module1.pyc' module2.__file__ 'mybase/mypkg/type1/module2.pyc' but I can't figure out how to do this. Thank you, Gabriel You might try something like the following: $ export PYTHONPATH=/home/ryles $ cat mybase_test.py import mybase mybase.type = type2 from mybase.mypkg import module0, module1, module2 print module0.__file__ print module1.__file__ print module2.__file__ $ python mybase_test.py /home/ryles/mybase/mypkg/module0.pyc /home/ryles/mybase/mypkg/type2/module1.pyc /home/ryles/mybase/mypkg/type2/module2.pyc $ ls -l mybase/ -rw-r--r-- 1 ryles None 44 Sep 20 16:59 __init__.py drwxr-xr-x+ 4 ryles None 0 Sep 20 17:06 mypkg $ cat mybase/__init__.py default_type = type1 type = default_type $ ls -l mybase/mypkg/ -rw-r--r-- 1 ryles None 307 Sep 20 17:06 __init__.py -rw-r--r-- 1 ryles None 0 Sep 20 16:51 module0.py drwxr-xr-x+ 2 ryles None 0 Sep 20 17:02 type1 drwxr-xr-x+ 2 ryles None 0 Sep 20 17:02 type2 $ ls -l mybase/mypkg/type1/ -rw-r--r-- 1 ryles None 0 Sep 20 16:49 __init__.py -rw-r--r-- 1 ryles None 0 Sep 20 16:49 module1.py -rw-r--r-- 1 ryles None 0 Sep 20 16:51 module2.py $ ls -l mybase/mypkg/type2/ -rw-r--r-- 1 ryles None 0 Sep 20 16:48 __init__.py -rw-r--r-- 1 ryles None 0 Sep 20 16:51 module1.py -rw-r--r-- 1 ryles None 0 Sep 20 16:49 module2.py $ cat mybase/mypkg/__init__.py # These modules are hard-coded. from mybase.mypkg import module0 # These modules are resolved dynamically. from mybase import type for module_name in [module1, module2]: full_name = mybase.mypkg. + type + '.' + module_name globals()[module_name] = __import__(full_name, {}, {}, [full_name]) $ -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
On Sep 19, 8:36 pm, Daniel Fetchinson fetchin...@googlemail.com wrote: the pyjamas project is taking a slightly different approach to achieve this same goal: beat the stuffing out of the pyjamas compiler, rather than hand-write such large sections of code in pure javascript, and double-run regression tests (once as python, second time converted to javascript under pyv8run, d8 or spidermonkey). anyway, just thought there might be people who would be intrigued (or horrified enough to care what's being done in the name of computer science) by either of these projects. I've added pyjamas to the implementations page on the Python Wiki in the compilers section: http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. it's strictly speaking, according to wikipedia, a language translator. i'm just in the process of adding an AST parser (based on lib2to3, from sgraham's work in skulpt) which will become the basis of an exec function, just like in the skulpt demo. also to answer your question: pyjamas has [roughly] two modes: -O and --strict. -O is the one where you have to write in a subset of python, and you can (unfortunately) do things like 5 + px (which doesn't throw an exception). this saves _vast_ amounts of CPU cycles. --strict as you would expect is the python-strict converter, where we're beginning to add implementations of __add__ etc. etc. and generally cope with the nasty grungy bits of javascript that would otherwise make arbitrary python applications keel over. l. -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
On Sep 20, 12:05 am, exar...@twistedmatrix.com wrote: Does pyjamas convert any Python program into a JavaScript program with the same behavior? that's one of the sub-goals of the pyjamas project, yes. I don't intend to imply that it doesn't - I haven't been keeping up with pyjamas development, so I have no idea idea. I think that the case *used* to be (perhaps a year or more ago) that pyjamas only operated on a fairly limited subset of Python. If this was the case but has since changed, it might explain why some people are confused to hear pyjamas called a Python implementation now. yup. -O now equals [roughly] pyjamas 0.3 to 0.5p1 behaviour, aka pythonscript - a mishmash of python grammar/syntax with javascriptic execution. since kees joined, he's been steaming ahead with python interoperability (--strict option). he first started out by improving the pyjamas compiler and support libraries to the point where the python version of http://puremvc.org could be compiled to javascript as-is, and it's gone from there, really. on the roadmap is to take a look at what the unladen/swallow team have done, when they get to their stage 2 unboxing, and see if calling out to PyV8 or Python-SpiderMonkey objects can be done from intobject.c, longobject.c etc. if the early experiments are anything to go by, python will then have _yet another_ python accelerator. but, really, for that to properly happen, python has _got_ to get some type-checking decorators on functions: @paramtypecheck(foo=int, bar=[int, str]) @paramtypecheck(int, [int, str]) # or this @returntypecheck(int) def randomfunction(foo, bar): if isinstance(bar, str): bar = int(bar) return foo + bar this kind of type-checking guidance would _drastically_ help out all of the compilers (such as that python-to-c++ one), and could probably also be utilised by http://python.org itself, ultimately, to speed up function execution. it's also just good software engineering practice to check parameters and return results. l. -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparison of parsers in python?
On Sep 20, 3:16 pm, Peng Yu pengyu...@gmail.com wrote: On Sun, Sep 20, 2009 at 1:35 PM, andrew cooke and...@acooke.org wrote: On Sep 20, 9:12 am, andrew cooke and...@acooke.org wrote: ps is there somewhere can download example files? this would be useful for my own testing. thanks. i replied to a lot of your questions here; any chance you could reply to this one of mine? the wig format looks like it could be a good test for lepl. I missed your question. I have only some files that I only use a subset of the syntax in wig. Here is one example. ah, thanks. i'll see if i can find something on the 'net - i am hoping to test how / whether gigabytes of data can be parsed. andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to class name and function name in a python program?
Peng Yu pengyu...@gmail.com wrote: What does @echo mean? Have you read _any_ of the documentation? Or is this all an exercise in seeing if you can convince a group of disparate strangers to teach you Python for free? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/MySQL Frustration
Dennis Lee Bieber wrote: On Sun, 20 Sep 2009 14:25:53 -0400, Victor Subervi victorsube...@gmail.com declaimed the following in gmane.comp.python.general: Hi; I have the following code: while i num: cat = 'cat' + str(i) cat = form.getfirst(cat, '') item = 'item' + str(i) item = form.getfirst(item, '') descr = 'descr' + str(i) descr = form.getfirst(descr, '') uom = 'uom' + str(i) uom = form.getfirst(uom, '') price = 'price' + str(i) price = form.getfirst(price, '') sql = 'Category=' + cat + ', Item=' + item + ', Description=' + descr + ', UOM=' + uom + ', Price=' + price + '' sql = 'insert into %s values (%s);' % (company, sql) cursor.execute(sql) i += 1 Forgive me, but that is a bit of a mess... And from what I can see, does not even generate valid insert statements unless MySQL has expanded the syntax greatly. You're probably throwing an exception at cursor.execute. Are you catching exceptions somewhere else? Also, you need to call commit() when you're done updating, or, at program exit, all your changes to the database will be undone, at least if you're using any of the database engines that do transactions. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
kakarukeys wrote: On Sep 20, 10:57 pm, Dave Angel da...@ieee.org wrote: kakarukeys wrote: On Sep 20, 6:24 pm, Dave Angel da...@ieee.org wrote: Jiang Fung Wong wrote: Dear All, Thank you for the information. I think I've some idea what the problem is about after seeing the replies. More information about my system and my script PIII 1Ghz, 512MB RAM, Windows XP SP3 The script monitors global input using PyHook, and calculates on the information collected from the events to output some numbers. Based on the numbers, the script then performs some automation using SendKeys module. here is the memory usage: firefox.exe, 69MB, 109MB svchost.exe, 26MB, 17MB pythonw.exe, 22MB, 17MB searchindexer.exe, 16MB, 19MB My first guess is that the script calculated for too long time after receiving an event before propagating it to the default handler, resulting the system to be non-responsive. I will try to implement the calculation part in another thread. Then the separate will have 100% CPU usage, hope the task scheduling of Windows works in my favour. (You top-posted this message, putting the whole stream out of order. So I deleted the history.) All my assumptions about your environment are now invalid. You don't have a CPU-bound application, you have a Windows application with event loop. Further, you're using SendKeys to generate a keystroke to the other process. So there are many things that could be affecting your latency, and all my previous guesses are useless. Adding threads to your application will probably slow the system down much more. You need to find out what your present problem is before complicating it. You haven't really described the problem. You say the system is unresponsive, but you made it that way by creating a global hook; a notoriously inefficient mechanism. That global hook inserts code into every process in the system, and you've got a pretty low-end environment to begin with. So what's the real problem, and how severe is it? And how will you measure improvement? The Task manager numbers are probably irrelevant. My first question is whether the pyHook event is calling the SendKeys function directly (after your lengthy calculation) or whether there are other events firing off in between. If it's all being done in the one event, then measure its time, and gather some statistics (min time, max time, average...). The task manager has far too simplistic visibility to be useful for this purpose. What else is this application doing when it's waiting for a pyHook call? Whose event loop implementation are you using? And the program you're trying to control -- is there perhaps another way in? DaveA Hi, Sorry I wasn't sure how to use Google groups to post a msg to the newsgroup, I used Gmail to write my previous reply. What you and the other guy have provided me isn't useless. Now I understand the non- responsiveness may not be caused by high CPU usage, as the OS, be it Windows or Linux, has a way to prioritize the tasks. This is a vital clue to me. By not responsive, I mean, for some time, the mouse pointer is not moving smoothly, to such extent that I can't do anything with the mouse. It's like playing a multi-player game on a connection with a lot of lag. It's not caused by global hook, because it happens under certain condition, i.e. when fpa.ProcessEvent(word) is computing. I included my main script for your reference. Comments: (1) The automation method tc.Auto() is slow, but it doesn't cause any problem, because the user would wait for the automation to finish, before he continues to do something. (2) all other methods invoked are fast, except fpa.ProcessEvent(word) (this information is obtained from profiling). It is this method that causes 100% CPU usage. I'm planning to move this method to a separate thread, so that OnEvent(event) can finish executing, while the separate thread goes on to finish its calculation. Is this a good idea? import pyHook import TypingAnalyzer import GUI def OnEvent(event): if hasattr(event, Key) and event.Ascii =9 and event.Key == Tab and event.Injected =0 and event.Alt == 0: tc.Auto() return False else: recognized =k.ProcessEvent(event) if recognized: tc.MatchChar(recognized) paragraph =c.ProcessEvent(recognized) if paragraph: for word in paragraph: fpa.ProcessEvent(word) return True hm =yHook.HookManager() hm.MouseAllButtonsDown =nEvent hm.KeyDown =nEvent hm.HookMouse() hm.HookKeyboard() rk =ypingAnalyzer.ReadKey() rc =ypingAnalyzer.ReadChar() fpa =TypingAnalyzer.Analysis() tc =ypingAnalyzer.Automation(fpa) if __name__
Is there a concerted effort afoot to improve the Python Wiki?
I've noticed over the past few weeks a huge increase in the frequency of edits in the Python wiki. Many of those are due to Carl Trachte's work on non-English pages about Python. There are plenty of other pages going under the knife as well though. Is there some community movement people are aware of to wrangle the wiki into better shape? Thanks, Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Can print() be reloaded for a user defined class?
Peng Yu wrote: On Sun, Sep 20, 2009 at 9:19 AM, Dave Angel da...@ieee.org wrote: Peng Yu wrote: snip you might use: Is __repr__ =tr__ copy by reference or by value? If I change __str__ later on, will __repr__ be changed automatically? Regards, Peng Reference or value? Neither one. This assignment is no different than any other attribute assignment in Python. Technically, it binds the name __repr__ to the function object already bound by __str__. You now have a second name pointing to the same object. Rebinding one of those names to yet another different object won't affect the other name. name1 =this is a test name2 =ame1 name1 =another string #this has no effect on name2 print name1, name2 I am more familiar with C++ than python. So I need to connect python concept to C++ concept so that I can understand it better. name1 and name are all references (in the C++ sense), right? __repr__ and __str__ are references (in the C++ sense) to functions and both of them could refer to the same function or two different ones, right? Regards, Peng By limiting yourself to C++ terminology, you're restricting how well you can understand it. But I'll try. C++ references cannot change. And C++ functions cannot be created on the fly. But otherwise, these names work kinda like C++ references. Perhaps it'd help if I try to describe how some of this stuff works. For now, let's skip classes entirely, and just deal with top-level stuff (global scope). Let's say we're in a module called mymodule.py. So there's an object called mymodule, with a dictionary in it containing some attributes This dictionary works just like any dictionary you might define, but it's under the covers, so to speak. You add stuff to this dictionary by doing an assignment. name1= value creates a new string object, and adds a dictionary item with key of name1 and value of pointer-to-the-string-object name2 = 42 does the same thing, but it's an int object. name1 = name2 doesn't create a new dictionary item, since it's already there. But it changes the value of the item from ptr-to-int to ptr-to-string. At this point, the string object doesn't have any refs, so it probably gets freed. And the int object has two refs. It doesn't know what they are, just that the count is two. def myfunct(): return 12 creates a code object, and adds a dictionary item with key of myfunct and value of pointer-to-the-code-object. otherfunct = myfunct creates a new dictionary item with the same value as the existing one. And ref count goes to two. Notice that there's nothing stopping you from doing name1 = myfunct and now name1 acts like a function, instead of a string or an int. All these things are first-class objects. One more piece for today's lesson: import othermodule This creates an entry in our module dictionary with key of othermodule and value pointing to the imported module. Now, we can get at our own symbols by name1, or name2. And we can get at symbols from othermodule by othermodule.name3 This simply finds othermodule in the current global dictionary, then looks up name3 in that othermodule's dictionary. Clearer ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are python module installed?
On Sun, Sep 20, 2009 at 6:30 PM, Peng Yu pengyu...@gmail.com wrote: Hi, I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin include lib share $ ls -R lib Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are python module installed?
On Sun, Sep 20, 2009 at 20:30 -0500, Peng Yu wrote: I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? Yes. $ ls bin include lib share ^^^ here with kind regards Wolodja Wentland signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are python module installed?
I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin include lib share Try 'ls lib/python*' and also 'ls lib/python*/site-packages/' HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a concerted effort afoot to improve the Python Wiki?
Hi Skip, I've noticed over the past few weeks a huge increase in the frequency of edits in the Python wiki. Many of those are due to Carl Trachte's work on non-English pages about Python. There are plenty of other pages going under the knife as well though. Is there some community movement people are aware of to wrangle the wiki into better shape? I'm sure you've been emailed a few times regarding my edits :-( There's currently a lot of things being discussed on divers...@python.org regarding improvements to the wiki and its possible use as a space for drafts to go up, it's possible that's where changes are originating... - Rami Chowdhury Never assume malice when stupidity will suffice. -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) On Sep 20, 2009, at 17:52 , s...@pobox.com wrote: I've noticed over the past few weeks a huge increase in the frequency of edits in the Python wiki. Many of those are due to Carl Trachte's work on non-English pages about Python. There are plenty of other pages going under the knife as well though. Is there some community movement people are aware of to wrangle the wiki into better shape? Thanks, Skip -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are python module installed?
On Sun, Sep 20, 2009 at 8:37 PM, Daniel Fetchinson fetchin...@googlemail.com wrote: I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin include lib share Try 'ls lib/python*' and also 'ls lib/python*/site-packages/' Do I need to set PYTHONPATH to lib/python* because I changed the default 'prefix'? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
testing code in python source package
Hi, I'm wondering if the development of python is test driven. If it is, where in the Python-2.6.2 source directory is the test code for the modules in ./Lib? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: How to get the minimum number that can be represented?
Peng Yu wrote: On Sun, Sep 20, 2009 at 9:37 AM, Grant Edwards inva...@invalid.invalid wrote: On 2009-09-20, Peng Yu pengyu...@gmail.com wrote: Suppose I want to define a function that return the minimum number that can be represented. def f(x): #body That it, if I call f(10), f will return the minimum integer that can be represented in the machine; if I cal f(10.5), f will return the minimum float that can be represented in the machine. Could somebody let me know what should be in the function body? The stuff you wan is in the sys module. For example: sys.float_info sys.floatinfo(max=7976931348623157e+308, max_exp24, max_10_exp08, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=07, dig, mant_digS, epsilon=2.2204460492503131e-16, radix=2, rounds=1) sys.maxint 2147483647 You might also want to read up on the type() builtin I want avoid using any 'if' statement. In C++, I can use template. How to do not use 'if' statement in python? Regards, Peng So if the homework assignment is for C++, do it in C++. If this is supposed to be some kind of programming challenge, then you need to state all the rules up front. For example, you could write something like def f(x): return [-10, 42][2*x - 20] and it'll return -10 for value 10 and 42 for value 10.5 Or: def f(x): result = raw_input(What's the smallest value of the same type as + str(x)) return result And of course if the constraint is not to use the if statement, and you can use Python 2.6, how about a conditional expression? -- http://mail.python.org/mailman/listinfo/python-list
Where are python module installed?
Hi, I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin include lib share Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: pyjamas pyv8run converts python to javascript, executes under command-line
the pyjamas project is taking a slightly different approach to achieve this same goal: beat the stuffing out of the pyjamas compiler, rather than hand-write such large sections of code in pure javascript, and double-run regression tests (once as python, second time converted to javascript under pyv8run, d8 or spidermonkey). anyway, just thought there might be people who would be intrigued (or horrified enough to care what's being done in the name of computer science) by either of these projects. I've added pyjamas to the implementations page on the Python Wiki in the compilers section: http://wiki.python.org/moin/implementation In what way is pyjamas a python implementation? As far as I know pyjamas is an application written in python that is capable of generating javascript code. it's strictly speaking, according to wikipedia, a language translator. Yep, this sounds more like what I originally had in mind. But if people insist on calling it a python implementation, it's fine by me :) Cheers, Daniel i'm just in the process of adding an AST parser (based on lib2to3, from sgraham's work in skulpt) which will become the basis of an exec function, just like in the skulpt demo. also to answer your question: pyjamas has [roughly] two modes: -O and --strict. -O is the one where you have to write in a subset of python, and you can (unfortunately) do things like 5 + px (which doesn't throw an exception). this saves _vast_ amounts of CPU cycles. --strict as you would expect is the python-strict converter, where we're beginning to add implementations of __add__ etc. etc. and generally cope with the nasty grungy bits of javascript that would otherwise make arbitrary python applications keel over. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a concerted effort afoot to improve the Python Wiki?
On Sep 20, 5:52 pm, s...@pobox.com wrote: I've noticed over the past few weeks a huge increase in the frequency of edits in the Python wiki. Many of those are due to Carl Trachte's work on non-English pages about Python. There are plenty of other pages going under the knife as well though. Is there some community movement people are aware of to wrangle the wiki into better shape? Thanks, Skip Yes, as Rami says, there are moves afoot. I've been working with Carl, who is no longer with divers...@python.org -- something of a hornets nest is you ask me. We're hoping to go open archive so it's not such a Chamber of Whispers. Here's an excerpt from the archive (subscribers only) for your edificiation. You'll find more at this Wiki page, which starts with the PSF version of the Diversity statement, developed independently of the private Aahz list initiative. http://wiki.python.org/moin/DiversityStatementDiscussion (I distance myself from this page, except for the PSF statement, as too punitive and threatening, also amateurish). I should put my cards on the table that I'm a Quaker animist and think training monkeys to write Hello world in Python might be a good way to improve user group diversity. -- Forwarded message -- From: kirby urner kirby.ur...@gmail.com Date: Tue, Sep 15, 2009 at 11:36 AM Subject: Fwd: [PSF-Members] All-positive diversity statement To: divers...@python.org snip Python is *not* just for humans at the end of the day (that's if you wanna talk diversity for real). misanthropic http://www.youtube.com/watch?v=c2hRrcvxRFE /misanthropic Not a direct quote from PSF version (polished it some): provocative == How about something like: Diversity Statement: Python is free and open source and is therefore deliberately placed in the public commons for all humans to use, other species if they gain this ability. If you're a racist, bigoted pig from hell whom nobody loves, and you choose to use Python, you're welcome. If anyone says you have no right to use Python, because of all the evil nonsense you pump out in the world, or because you're untouchable (for some reason), they're wrong. You may be in prison for other offenses, but using Python will never be one of them Using Python is not a crime. Just use it. That being said, the PSF does protect against counterfeits so if you change the source in any way and try to conceal this, while pretending you're sharing the real Python, expect repercussions. That's an offense. Expect retaliation. /provocative joke Send your comments, suggestions for revisions directly to snake...@python.org (never mind the error message -- everyone gets those) /joke Kirby -- http://mail.python.org/mailman/listinfo/python-list
Re: testing code in python source package
Peng Yu pengyu...@gmail.com wrote: I'm wondering if the development of python is test driven. If it is, where in the Python-2.6.2 source directory is the test code for the modules in ./Lib? Unsurprisingly, they're located in Lib/test. Is it _really_ that difficult to find? -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)
On Sep 19, 11:02 pm, Ben Morrow b...@morrow.me.uk wrote: [This is not a Perl question. F'ups set to c.l.python.] Heh, I didn't notice the cross-post. Glad I decided against following up with minor philosophical rant. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are python module installed?
Peng Yu schrieb: On Sun, Sep 20, 2009 at 8:37 PM, Daniel Fetchinson fetchin...@googlemail.com wrote: I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin include lib share Try 'ls lib/python*' and also 'ls lib/python*/site-packages/' Do I need to set PYTHONPATH to lib/python* because I changed the default 'prefix'? It would have taken shorter to *try* that than it would to write this mail. So go, try it. Hint: import foo foo.__file__ Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are python module installed?
On Sun, Sep 20, 2009 at 10:25 PM, Diez B. Roggisch de...@nospam.web.de wrote: Peng Yu schrieb: On Sun, Sep 20, 2009 at 8:37 PM, Daniel Fetchinson fetchin...@googlemail.com wrote: I configured python-2.6.2 with my own --prefix, then 'make' and 'make install'. I only find the following dirs and I don't find any python modules in the directory. Do python modules come with python-2.6.2? $ ls bin include lib share Try 'ls lib/python*' and also 'ls lib/python*/site-packages/' Do I need to set PYTHONPATH to lib/python* because I changed the default 'prefix'? It would have taken shorter to *try* that than it would to write this mail. So go, try it. Hint: import foo foo.__file__ The newly compiled python does pick up the newly installed module. How does it do so? Is the module path hard coded in the python executable when the executable is compiled? Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming ideas?
You could learn a lot of Python contributing to docutils or bibstuff, and if you write papers or presentations, it may pay off directly. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Sun, 20 Sep 2009 13:27:07 -0700, daggerdvm wrote: Write the definition of a function twice , that receives an int parameter and returns an int that is twice the value of the parameter. how can i do this Yes, that certainly is an easy question. Here's my solution: class MultiplierFactory(object): def __init__(self, factor=1): self.__factor = factor @property def factor(self): return getattr(self, '_%s__factor' % self.__class__.__name__) def __call__(self, factor=None): if not factor is not None is True: factor = self.factor class Multiplier(object): def __init__(self, factor=None): self.__factor = factor @property def factor(self): return getattr(self, '_%s__factor' % self.__class__.__name__) def __call__(self, n): return self.factor*n Multiplier.__init__.im_func.func_defaults = (factor,) return Multiplier(factor) twice = MultiplierFactory(2)() It needs some error checking, but otherwise should work. Ever-helpful-ly y'rs, -- Steven -- http://mail.python.org/mailman/listinfo/python-list