Re: subprocess -popen - reading stdout from child - hangs
[EMAIL PROTECTED] wrote: Let's say I have this Python file called loop.py: import sys print 'hi' sys.stdout.flush() while 1: pass And I want to call it from another Python process and read the value 'hi'. How would I do it? So far I have tried this: proc = subprocess.Popen('python /home/chiefinnovator/loop.py',shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE) proc.stdout.read() From python documentation `read([size])' Read at most SIZE bytes from the file (less if the read hits `EOF' before obtaining SIZE bytes). If the SIZE argument is negative or omitted, read all data until `EOF' is reached. The bytes are returned as a string object. An empty string is returned when `EOF' is encountered immediately. (For certain files, like ttys, it makes sense to continue reading after an `EOF' is hit.) Note that this method may call the underlying C function `fread()' more than once in an effort to acquire as close to SIZE bytes as possible. Also note that when in non-blocking mode, less data than what was requested may be returned, even if no SIZE parameter was given. read call in your code is waiting for EOF, since the script never exits EOF is not reached. Change read code to proc.stdout.readline() or remove while 1 loop from loop.py. HTH Kolla -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
On 22 Sep., 23:17, Erik Max Francis [EMAIL PROTECTED] wrote: The attribute and method (not made distinct in Io; they're called slots) is much the same as with Python; the current instance is checked for the object, then its parents, then _its_ parents, and so on. Repeating the same point as Marc doesn't mean that I have to repeat my reply as well. Doesn't it? -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess -popen - reading stdout from child - hangs
On Sep 22, 8:28 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Let's say I have this Python file called loop.py: import sys print 'hi' sys.stdout.flush() Add sys.stdout.close() while 1: pass And I want to call it from another Python process and read the value 'hi'. How would I do it? So far I have tried this: proc = subprocess.Popen('python /home/chiefinnovator/loop.py',shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE) proc.stdout.read() But it just hangs at read() proc.communicate() also just hangs. What am I doing wrong? Please advise. Since your loop.py is still alive and hasn't closed its stdout, the caller continues to wait for EOF (it doesn't know if loop.py is done generating all its output) Karthik Thanks, Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: glob on windows os.renames creates many nested folders
crybaby wrote: when I do this in my python code and run it in windows xp, it creates ctemp//.../.../../ so on and creates file t. Not file starting with the name complist and ending with .txt (complist*.txt). Any idea why this may be? glob only works in *nix not on windows? os.renames(glob.glob('complist*.txt') [0],r'temp/'.join(glob.glob('complist*.txt')[0])) Python does what you tell it. Let's assume glob.glob(complist*.txt) ['complist001.txt', 'complist002.txt'] The first argument to os.renames() is then 'complist001.txt' and the second is 'temp/'.join('complist001.txt'), or temp/.join(complist001.txt) 'ctemp/otemp/mtemp/ptemp/ltemp/itemp/stemp/ttemp/0temp/0temp/1temp/.temp/ttemp/xtemp/t' that is the join() method interprets the string complist001.txt as the character sequence [c, o, m, ...] and stuffs a temp/ between c and o, o and m, ... What you want instead is just temp/ + complist001.txt or, written in an os-independent way, os.path.join(temp, complist001.txt) where a path separator is added automatically. Your code then becomes fn = glob.glob(complist*.txt)[0] # don't call stuff like that twice os.renames(fn, os.path.join(temp, fn)) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Scott David Daniels wrote: Ron Adam wrote: Scott David Daniels wrote: Cristian wrote: On Sep 21, 3:44 pm, Ron Adam [EMAIL PROTECTED] wrote: I think key may be to discuss names and name binding with your friend. Here's an idea: import math def sin_integral(start, finish, dx): ... def cos_integral(start, finish, dx): ... generalize and separate the integration technique from the function it integrates. How about this? It's based on the apple basic program example in How to Enjoy Calculus. Ron import math def integrate(fn, x1, x2, n=100):... def fn(x): ... print Area of fn:, integrate(fn, 0, 2) print Area of cos fn:, integrate(math.cos, 1, 2) The point was a pedagogic suggestion, i.e. I understood your point. I just found it interesting since I've been trying to extend my math (for use with python) skills in this area. Try taking your friend along this path. I wasn't trying to do a particularly good job integrating, simply trying to show how you could motivate first-class functions by showing a useful and fun (at least to an engineer) function that cries out for higher order functions. In my experience engineers often want a reason its useful before engaging with an idea. I'll bet that after a few such experiences he'll see how passing around functions and (later) making functions from from functions is a great tool to have in his toolbox. Once he sees that, there will be no problem. Yes, I agree. Another useful thing I've found is to store functions in a dictionary and call them (dispatching) based on some data value. Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Factory function with keyword arguments
Steven D'Aprano wrote: I'm writing a factory function that needs to use keywords in the produced function, not the factory. Here's a toy example: I thought of doing this: def factory(flag): if flag: kw = 'spam' else: kw = 'ham' def foo(obj, arg): kwargs = dict([(kw, arg)]) return obj.method(**kwargs) return foo Is this the best way of doing this? Are there any alternative methods that aren't risky, slow or obfuscated? Looks ok to me. It can be simplified a bit. def factory(flag): kw = 'spam' if flag else 'ham' def foo(obj, arg): return obj.method(**{kw:arg}) return foo Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Factory function with keyword arguments
On 9/23/07, Ron Adam [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: I'm writing a factory function that needs to use keywords in the produced function, not the factory. Here's a toy example: http://docs.python.org/whatsnew/pep-309.html -- http://mail.python.org/mailman/listinfo/python-list
directpython question
Hello, I've got IBM Thinkpad 30 laptop with configuration: IBM Thinkpad R30 P3 Mobile Celeron 900mhz 128mb sdram pc133 15gb hdd cd-rom Teac cd-224e 56K V.90/92 10/100 Ethernet lpt port ps2 port 2 x usb port vga-out pcmcia ,then I have been install directx 9.0c,Python 2.5 and directpython for python 2.5.On my two computers directpython works but on this laptop it don't want work e.g: When I want execute this script on laptop: import d3dx frame=d3dx.Frame(u'SOME FRAME') frame.mainloop() I get this error: Traceback (most recent call last): File C:\Python25\Lib\site-packages\veki1.py, line 2, in module fr=d3dx.Frame(u'SOME FRAME') File C:\Python25\lib\site-packages\directpy\d3dx.py, line 639, in __init__ self._createDevice(area[2:4]) File C:\Python25\lib\site-packages\directpy\d3dx.py, line 659, in _createDevice raise RuntimeError(No valid mode found) RuntimeError: No valid mode found Regards, Vedran -- http://mail.python.org/mailman/listinfo/python-list
Naples is burning
Please, dear Mr Bush: we don't have weapons of destruction mass, but bomb my people and save us. Please, dear old friend Vesuvio: wake up and save us. Please, dear Jesus Christ: give us the Big One and save us... http://www.youtube.com/watch?v=eU3fNRcBtQw -- http://mail.python.org/mailman/listinfo/python-list
Re: Factory function with keyword arguments
On Sun, 23 Sep 2007 03:55:45 -0500, Ron Adam wrote: Steven D'Aprano wrote: I'm writing a factory function that needs to use keywords in the produced function, not the factory. Here's a toy example: [snip] Thanks everyone who answered, you've given me a lot of good ideas. I've run some tests with timeit, and most of the variants given were very close in speed. The one exception was (not surprisingly) my version that builds a tuple, puts it in a list, then converts it to a dict, *before* doing anything useful with it. It was 3-4 times slower than the others. George's version, with two definitions of foo(), was the fastest. The second fastest was the variant using exec, which surprised me a lot. I expected exec to be the slowest of the lot. Unfortunately, I doubt that these would scale well as the factory becomes more complicated. Excluding those two, the next fastest was the original code snippet, the one I rejected as clearly too slow! It's apparently faster to check a flag than it is build and then expand a dict for keyword arguments. A valuable lesson... always measure before guessing whether code will be slow or not. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Factory function with keyword arguments
Steven D'Aprano [EMAIL PROTECTED] writes: A valuable lesson... always measure before guessing whether code will be slow or not. And after measuring, don't guess then either :-) -- \Science doesn’t work by vote and it doesn’t work by | `\ authority. —Richard Dawkins, Big Mistake (The Guardian) | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: An Editor that Skips to the End of a Def
Paul Rubin http://[EMAIL PROTECTED] writes: [EMAIL PROTECTED] (John J. Lee) writes: I think mousing takes more mental work than typing, I'm not sure this is a matter for debate, as much as physical measurement. I don't know of any way to physically measure mental work. fMRI is one. That won't directly answer the question of course -- but then physical measurement and scientific progress are never direct, theory is always involved. John -- http://mail.python.org/mailman/listinfo/python-list
newb: Question regarding custom exception
Why you specify type and name of the exception in your custom exceptions, but not in built in exceptions except IOError: print no file by the name ccy_rates*.txt except MyError, e: print e.msg Also, when you do: try: raise MyError(23) In try: MyError(23) , you are calling MyError class, but actually get instantiated in except MyError, e: ? -- http://mail.python.org/mailman/listinfo/python-list
annoying stdin/stdout + pipes problem
Hi, I want to create a program that reads input from stdio that can prompt a user for input while doing so without getting into problems. A simplified version of what I want: I have an input file ***cat input.txt foo bar baz fubar barooba xyxxyt raboof txet black knight And a file that replaces certain words ***cat replace2.py from sys import stdin, stdout def censor(foo, bar, input): return input.replace(foo, bar) # i = raw_input('Remove what? ').strip() # o = raw_input('Replace %s with what? ' %i).strip() for line in stdin.xreadlines(): line = censor('foo', 'candy', line) line = censor('bar', 'donkey', line) line = censor('baz', 'hare rama', line) # line = censor(i, o, line) stdout.write(line) ***cat input.txt | python replace2.py candy donkey hare rama fudonkey donkeyooba xyxxyt raboof txet black knight As you can see I have commented out what I'd like to do but do not know how to. Can I somehow halt the previous print to stdout (cat input.txt) - if so can I then start it again, and how? I want to use this to use it in a small encryption program called txet in order to do something like this: tar -blabla ~ | gzip -blabla | txet -e -stdin -stdout /tmp/ home.tar.gz.txet Of course I want to use it to get the password from the user. Thanks, Per PS: a prototype can be downloaded from www.txet.org -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: Question regarding custom exception
On Sun, 23 Sep 2007 05:32:28 -0700, crybaby wrote: Why you specify type and name of the exception in your custom exceptions, but not in built in exceptions except IOError: print no file by the name ccy_rates*.txt except MyError, e: print e.msg You can say: except IOError, e: print e.msg And you can say: except MyError: print whatever I want It all depends on what you want to do. Also, when you do: try: raise MyError(23) In try: MyError(23) , you are calling MyError class, but actually get instantiated in except MyError, e: ? I don't understand what you are actually asking, but I will try my best. raise MyError(23) calls the class MyError and creates and instance, and that instance is then used as an argument to the raise statement. You can also do this: instance = MyError(23) raise instance You don't need the try block unless you want to catch the exception. The exception itself it actually raised by the raise statement, not the except statement. The except statement _catches_ the exception. Try typing these lines in the interactive interpreter: try: print before the exception raise Exception(an error occurred) print this line is never executed print neither is this except Exception, e: print the exception is: print e print e.message Hope this helps. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: Question regarding custom exception
crybaby [EMAIL PROTECTED] wrote: Why you specify type and name of the exception in your custom exceptions, It's up to you, if you're interested in the actual exception object you catch it, otherwise not. Take a look at this: http://boodebr.org/main/python/tourist/taking-exception -- Lawrence, oluyede.org - neropercaso.it It is difficult to get a man to understand something when his salary depends on not understanding it - Upton Sinclair -- http://mail.python.org/mailman/listinfo/python-list
building a GUI
if i were up to make a GUI chich are the advantages of choosing python over matlab or java? -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting rid of bitwise operators in Python 3?
: arguments and dicts, which are lot more versatile. Another major use, : talking to hardware, is not something oft done in Python either. Are you sure? I've been doing lots of exactly that for 4 years, and I'm not the only one round here... Python makes an excellent language for talking to hardware. cds -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? This question is WAY to broad to give sane advice. You might want to state your context, objectives and restrictions are. Since you brought up Matlab, I suspect you're going after a scientific problem, involving data entry and display. In that case I'd say you're pretty well off using Matlab, since, well, it specific purpose is just that (GUI-wise, I mean). /W -- http://mail.python.org/mailman/listinfo/python-list
Re: can I run pythons IDLE from a command line??
On Sat, 22 Sep 2007 17:53:09 +0200, Thomas Jollans wrote: On Saturday 22 September 2007, [EMAIL PROTECTED] wrote: Hi, Is their a version of pythons IDLE that will run in a dos command line? The reason is that I would like to be able to run python code interactively from my parable by connecting to my desktop using remote command line or a telnet program. The Python interpreter should do fine. If your PATH environment variable is set up correctly, just run python, otherwise it's somewhere in your Python installation directory. If you don't want to miss IDLE's advantages, `IPython http:// ipython.scipy.org/moin/`_ might be interesting for you. Stargaming -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? As MatLab has a very lousy GUI, any other language would be an advantage ;-) The best is Delphi, second is VB, then comes SciLab, Python, etc I don't know where Java fits in. But as Wildemar said, your question is much to broad. cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: annoying stdin/stdout + pipes problem
I want to create a program that reads input from stdio that can prompt a user for input while doing so without getting into problems. ... As you can see I have commented out what I'd like to do but do not know how to. Can I somehow halt the previous print to stdout (cat input.txt) - if so can I then start it again, and how? The trick (which works on Linux for sure) is to open /dev/tty and ask question/get input on/from it. fp = open('/dev/tty', 'r+') fp.write('Prompt: ') answer = fp.readline().strip() I'm not usre for other *nix-es, and on Windows this will surelly not work -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
On Sep 23, 4:28 pm, stef mientki [EMAIL PROTECTED] wrote: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? As MatLab has a very lousy GUI, any other language would be an advantage ;-) The best is Delphi, second is VB, then comes SciLab, Python, etc I don't know where Java fits in. But as Wildemar said, your question is much to broad. cheers, Stef Form a newbie's point of view, Java's Swing Libraries (gui stuff) are pretty easy to get to grips with, if a bit big. They are also incredibly well documented, and are distributed by sun with the core language. Compared to most python toolkits, they are approximately as complex, but far better documented. The other good thing compared to python is their integration at the language API level rather than as a supplementary module. A quick look at the 1.6 swing tutorial will tell you whether this is something you'd like to use: http://java.sun.com/docs/books/tutorial/uiswing/start/index.html hope this helps brice -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing Object Data to Disk
I would like to know if Pickling the class object is the only way of writing it to disk for persistent storage. Also, do we have a concept similar to array of objects in Python? The number of objects is only known at run-time. Have a look at YAML. http://freshmeat.net/projects/syck/ Also it is possible to persist python data to and from XML. See xml.marshal.generic.dumps -- http://mail.python.org/mailman/listinfo/python-list
Re: Factory function with keyword arguments
Steven D'Aprano wrote: On Sun, 23 Sep 2007 03:55:45 -0500, Ron Adam wrote: Steven D'Aprano wrote: I'm writing a factory function that needs to use keywords in the produced function, not the factory. Here's a toy example: [snip] Thanks everyone who answered, you've given me a lot of good ideas. I've run some tests with timeit, and most of the variants given were very close in speed. The one exception was (not surprisingly) my version that builds a tuple, puts it in a list, then converts it to a dict, *before* doing anything useful with it. It was 3-4 times slower than the others. George's version, with two definitions of foo(), was the fastest. The second fastest was the variant using exec, which surprised me a lot. I expected exec to be the slowest of the lot. Unfortunately, I doubt that these would scale well as the factory becomes more complicated. The one with exec (the others less so) will depend on the ratio of how often the factory is called vs how often the foo is called. If the factory is called only once, then exec only runs once. If the factory is called every time foo is needed, then it will be much slower. So your test needs to take into account how the factory function will be used in your program also. Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: An Editor that Skips to the End of a Def
Matthew Woodcraft [EMAIL PROTECTED] writes: Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: http://www.asktog.com/SunWorldColumns/S02KeyboardVMouse3.html An interesting story. They say they picked a test for the express purpose of proving that in some circumstances cursor keys can be faster than the mouse, but came up with an exercise in which, unusually, the keyboard part can be performed with one hand, so eliminating the bit where the other hand moves from the keyboard to the mouse and back. -M- It's quite funny, that what the author proposes as to make it even harder actually speeds up the test for the mouse-users quite a bit. And cursor keys? Please, every self respecting editor has ways for moving around quite a bit more efficiently. And on top of that a use case, which no one in his right mind would do this way. Accomplishing this task with search-and-replace would have taken about 10 seconds. With Mouse or Keyboard. Regards, Manuel -- A hundred men did the rational thing. The sum of those rational choices was called panic. Neal Stephenson -- System of the world http://www.graune.org/GnuPG_pubkey.asc Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A 5828 5476 7E92 2DB4 3C99 -- http://mail.python.org/mailman/listinfo/python-list
Re: [Bulk] Re: Writing Object Data to Disk
On Sun, 2007-09-23 at 18:34 +0200, David wrote: I would like to know if Pickling the class object is the only way of writing it to disk for persistent storage. Also, do we have a concept similar to array of objects in Python? The number of objects is only known at run-time. Have a look at YAML. http://freshmeat.net/projects/syck/ Also it is possible to persist python data to and from XML. See xml.marshal.generic.dumps Thanks David :-) I appreciate the XML related comment, but as of now I am ready-to-roll with Python specific pickling. XML will be used in a later version of my code! Regards, Amit -- Amit Kumar Saha me blogs@ http://amitksaha.blogspot.com URL:http://amitsaha.in.googlepages.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I could use some help making this Python code run faster using only Python code.
Yes, Digital Mars D is what I was referring to and yes I know D is not as efficient as C++. If I knew of a good C++ compiler that is not from Microsoft that works natively with Windows I would be happy to consider using it. I've had good luck with MinGW (gcc compiled for windows). http://www.mingw.org Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) I would certainly suggest Python very much for any kind of gui. -- http://mail.python.org/mailman/listinfo/python-list
Untrusted python code
Hi, I have an application for which I want users to be able to make themes. I've planed a rather advanced model (in xml), which gives themes the option to redefine various drawing methods. Now I don't want those themes to be able to take over the current user, but I'd still like the scripts to be able to import stuff like math. Is there a way to ensure no IO and other dangerous stuff is done? -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation I would certainly suggest Python very much for any kind of gui. I agree to that ;-) cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
stef mientki schrieb: Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation Sounds like PyQt for me. Best GUI-designer I know, tremendous speed in development, giant sized lib that does all kinds of stuff is brilliantly designed + professional grade docus. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Preemption in python
On Sat, 2007-09-22 at 19:28 -0700, Kurtis Heimerl wrote: Hi, I'm developing my first python application, a multi-threaded cell phone gadget on ubuntu 7.10. I've just split off my first thread, and I've noticed something extremely strange: There doesn't seem to be any preemption. There are currently two threads, one that pings a storage service to see if there are messages available, and the other that runs the gtk windows. If I do not explicitly yield either one, it runs forever. I'm assuming this is a setting somewhere, but that's a very strange default behavior. How do I get this to go about preempting these threads? Any advice would be helpful. Thanks! I'm far from an expert in threaded Python applications, but threading ought to work out of the box. By default the Python interpreter will switch threads every 100 bytecode instructions (http://docs.python.org/api/threads.html). Note that if you are synchronizing around a lock, you may need to sleep before trying to reacquire the the lock to completely exit the critical section. A good overview of this (and the Python threading model) can be found at http://linuxgazette.net/107/pai.html -- Evan Klitzke [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Preemption in python
I ran a brief program to just test the threading properties of my VM, it seems to be preempting that application. Are there any interesting locks in the gtk package that I might not be playing well with? The reader thread that only runs on a blocking call is at the end of my response. I'll explain a bit more. This thread is spawned, I also have the main thread running a gtk windowed gui. The gui has it's own threads to deal with button presses and such. The problem is that the gui never seems to let anyone else run. Only on button presses that cause blocking calls ( ossaudiodev.audio.read for instance) does the reader thread print anything. Likewise, this thread blocks the GUI thread. There's really just no preemption at all going on, and it's exceedingly strange. The GIL locking could be part of my problem. I'm not explicitly releasing any locks, I have not used the lock interface at all. That shouldn't cause the behavior I'm seeing though right? class ReaderThread( threading.Thread ): def __init__(self, dtn): self.dtn = dtn threading.Thread.__init__(self) def run(self): print(RUNNING) while(True): bundle = api.recv(self.dtn.handle, DTN_PAYLOAD_MEM, 10) if(bundle): print(RECEIVED BUNDLE) else: print(NO BUNDLE) Thanks for the help, I really appreciate it. I'm totally blocked on this without you folk's help. On 9/23/07, Evan Klitzke [EMAIL PROTECTED] wrote: On Sat, 2007-09-22 at 19:28 -0700, Kurtis Heimerl wrote: Hi, I'm developing my first python application, a multi-threaded cell phone gadget on ubuntu 7.10. I've just split off my first thread, and I've noticed something extremely strange: There doesn't seem to be any preemption. There are currently two threads, one that pings a storage service to see if there are messages available, and the other that runs the gtk windows. If I do not explicitly yield either one, it runs forever. I'm assuming this is a setting somewhere, but that's a very strange default behavior. How do I get this to go about preempting these threads? Any advice would be helpful. Thanks! I'm far from an expert in threaded Python applications, but threading ought to work out of the box. By default the Python interpreter will switch threads every 100 bytecode instructions (http://docs.python.org/api/threads.html). Note that if you are synchronizing around a lock, you may need to sleep before trying to reacquire the the lock to completely exit the critical section. A good overview of this (and the Python threading model) can be found at http://linuxgazette.net/107/pai.html -- Evan Klitzke [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: database persistence with mysql, sqlite
coldpizza wrote: I want to run a database query and then display the first 10 records on a web page. Then I want to be able to click the 'Next' link on the page to show the next 10 records, and so on. My question is how to implement paging, i.e. the 'Next/Prev' NN records without reestablishing a database connection every time I click Next/Prev? Is it at all possible with cgi/mod_python? Caching database connections works in mod_python; not so much with cgi. For example, in a NON-web environment, with sqlite3 and most other modules, I can establish a database connection once, get a cursor object on which I run a single 'SELECT * FROM TABLE' statement and then use cursor.fetchmany(NN) as many times as there are still results left from the initial query. How do I do the same for the web? Short answer: you don't. It would mean saving cursors with partial query results, and arranging for incoming requests to go to the right process. Web-apps avoid that kind of thing. Many web toolkits offer session objects, but do not support saving active objects such as cursors. That said, I've never tried what you proposing with the tools you name. Depending on how your database handles transactions, an open cursor can lock-out writers, and even other readers. How long do you keep it around if the user doesn't return? What should happen if the user re-loads a page from a few sets-of-10 back? I am not using any high-level framework. I am looking for a solution at the level of cgi or mod_python (Python Server Pages under Apache). To call cursor.fetchmany(NN) over and over I need to pass a handle to the database connection but how do I keep a reference to the cursor object across pages? I use mysql and sqlite3 as databases, and I am looking for an approach that would work with both database types (one at a time). So far I have successfully used the following modules for database access: sqlite3, mysqld, and pyodbc. So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1 and L2 define the range for the 'Next' and 'Previous' commands. I have to run the query every time a click a 'Next/Prev' link. You might want to run that query by a MySQL expert. The basic method is nice in that it needs no server-side state between requests. (It's a little squirrely in that it can show a set of records that was never the contents of the table.) But I am not sure that this is the best and most efficient way. I suppose using CURSOR.FETCHMANY(NN) would probably be faster and nicer but how do I pass an object reference across pages? Is it possible without any higher-level libraries? Do you know that you have a performance problem? If so do you know that it is due to too many cursor.execute() calls? Keeping partially-executed queries is way down on the list of optimizations to try. What would be the proper way to do it on a non-enterprise scale? With mod_python, you can cache connections, which may help. If you use ORDER BY with LIMIT, the right index can make a big difference. Have you considered implementing your 'Next/Prev' commands on the browser side with Javascript? The server could then get all the records in one query, and the user would see point-in-time correct results. Another possibility is to the get all the query results and save them in a session object, then deal them out a few at a time. But as a rule of thumb, the less state on the server the better. Would SqlAlchemy or SqlObject make things easier with regard to database persistence? Quite likely, but probably not in the way you propose. The web frameworks that use those toolkits try to do things in robust and portable ways. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Untrusted python code
Thomas Dybdahl Ahle [EMAIL PROTECTED] writes: Hi, I have an application for which I want users to be able to make themes. I've planed a rather advanced model (in xml), which gives themes the option to redefine various drawing methods. Now I don't want those themes to be able to take over the current user, but I'd still like the scripts to be able to import stuff like math. Is there a way to ensure no IO and other dangerous stuff is done? No. There used to be something called rexec/bastion but it was removed because it was insecure. You might look at http://webpy.org which is a web kit written in Python, that has its own sandboxed interpreter for a Python-like user templating language, for doing what you're doing. You could also consider using something like client side XSLT. -- http://mail.python.org/mailman/listinfo/python-list
Travel around the globe...
http://world-traveling-destinations.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Latest software downloads!!!!!
http://freesoftwareupgrades.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
On 9/23/07, Diez B. Roggisch [EMAIL PROTECTED] wrote: stef mientki schrieb: Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation Sounds like PyQt for me. Best GUI-designer I know, tremendous speed in development, giant sized lib that does all kinds of stuff is brilliantly designed + professional grade docus. Diez -- http://mail.python.org/mailman/listinfo/python-list I'll have to agree completely here, Qt is just so great to work with. It makes my day job (I have to do it in C++) much more bearable. Phil Thompson (who maintains PyQt) is also very responsive and updates frequently even if you haven't bought a commercial licence for it. I also have to agree that the Qt Designer is the best I've ever had to work with, and I can't think of an instance where Qt Assistant wasn't open on one desktop or another. -- Kelvie -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
Diez B. Roggisch wrote: stef mientki schrieb: Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation Sounds like PyQt for me. Best GUI-designer I know, tremendous speed in development, giant sized lib that does all kinds of stuff is brilliantly designed + professional grade docus. Could well be, but I never looked at PyQt seriously, because of their weird license. cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
On 9/23/07, Diez B. Roggisch [EMAIL PROTECTED] wrote: stef mientki schrieb: Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation Sounds like PyQt for me. Best GUI-designer I know, tremendous speed in development, giant sized lib that does all kinds of stuff is brilliantly designed + professional grade docus. Diez -- http://mail.python.org/mailman/listinfo/python-list I'll have to agree completely here, Qt is just so great to work with. It makes my day job (I have to do it in C++) much more bearable. Phil Thompson (who maintains PyQt) is also very responsive and updates frequently even if you haven't bought a commercial licence for it. I also have to agree that the Qt Designer is the best I've ever had to work with, and I can't think of an instance where Qt Assistant wasn't open on one desktop or another. -- Kelvie -- http://mail.python.org/mailman/listinfo/python-list
Re: os.popen and lengthy operations
On 20 sep 2007, at 08.31, Dmitry Teslenko wrote: Hello! I'm using os.popen to perform lengthy operation such as building some project from source. It looks like this: def execute_and_save_output( command, out_file, err_file): import os def execute_and_save_output( command, out_file, err_file): (i,o,e) = os.popen3( command ) try: for line in o: out_file.write( line ) for line in e: err_file.write( line ) finally: i.close() o.close() e.close() ... execute_and_save_output( 'some long to run command', out_file, err_file) Problem is that script hangs on operations that take long to execute and have lots of output such as building scripts. -- Your problem is that you are not reading the standard output and standard error streams in the correct way. You need to do the reading of standard out and standard err in parallell rather than sequentially. The called process can't proceed when it's output buffers are full. Pipes is limited by small buffers (for examples 512 bytes on Mac OS X) - This sig is dedicated to the advancement of Nuclear Power Tommy Nordgren [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Small changes in side library
En Sat, 22 Sep 2007 22:07:27 -0300, [EMAIL PROTECTED] [EMAIL PROTECTED] escribi�: I have the side library which provides wide set of different functions, but I'm going to replace some of them with mine and provided such 'modified' library thought my project. The following way works well for my purpose: --- mylib.py --- import sidelib import os, sys, def func(): . sidelib.func = func .. ?!?!?!?! -- But this cause to write mylib.sidelib.func() to function call, is it any way to 'map' definitions from sidelib to mylib (possible at point marked ?!?!?!?!) such that constructions like mylib.func() will be provided and client code don't see difference between changed and original library in syntax way? Your code already works as you like: import sidelib sidelib.func() and you get the modified function. You don't have to say mylib.sidelib.func - in fact, mylib.sidelib is the same module object as sidelib But you have to ensure that the replacing code (mylib.py) runs *before* anyone tries to import something from sidelib. One my idea was to do from sidelib import * and then modify globals() dictionary, but this isn't good too because mylib imports many other modules and they all mapped into it's namespace (like mylib.os, mylib.sys). As you said, a bad idea. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Preemption in python
En Sun, 23 Sep 2007 16:10:03 -0300, Kurtis Heimerl [EMAIL PROTECTED] escribi�: I'll explain a bit more. This thread is spawned, I also have the main thread running a gtk windowed gui. The gui has it's own threads to deal with button presses and such. The problem is that the gui never seems to let anyone else run. Only on button presses that cause blocking calls ( ossaudiodev.audio.read for instance) does the reader thread print anything. Google for python gtk threading tutorial -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Ron Adam wrote: Scott David Daniels wrote: Ron Adam wrote: How about this? def integrate(fn, x1, x2, n=100):... The point was a pedagogic suggestion, ... I understood your point. I just found it interesting since I've been trying to extend my math (for use with python) skills in this area. Ah, sorry. I had realized I wasn't explicit in my first message. Yes, a perfectly fine integration. You can then (and this is a major jump to get used to): import functools Sine = functools.partial(integrate, math.cos, 0.0, n=100) Similarly, you can define a derivative that will behave fairly well, all without examining the definition of the function being operated upon. -Scott -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
On Sunday 23 September 2007, stef mientki wrote: Diez B. Roggisch wrote: stef mientki schrieb: Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation Sounds like PyQt for me. Best GUI-designer I know, tremendous speed in development, giant sized lib that does all kinds of stuff is brilliantly designed + professional grade docus. Could well be, but I never looked at PyQt seriously, because of their weird license. It's not weird. It's either GPL or proprietary. Your choice. That's as complicated as it gets. Phil -- http://mail.python.org/mailman/listinfo/python-list
strange behavious of the logging module?
Hi, having the following code: import logging logging.basicConfig(level=logging.ERROR, format='%(levelname)-8s %(message)s', filename='mc_rigid.log', filemode='w') # define a Handler which writes INFO messages or higher to the sys.stderr console = logging.StreamHandler() console.setLevel(logging.INFO) # set a format which is simpler for console use formatter = logging.Formatter('%(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) I observe nothing printed on the console. However if I change the level (just after the import) from logging.ERROR to logging.DEBUG I do see all info lines on the console as intended. Can anybody tell my mistake? I thought changing the level in basicConfig would have no impact on the following StreamHandler instance. Also, adding %(funcName)-8s to the formatter in basigConfig does not work for me: instead of the functions name the level in lower case gets inserted into the logfile. My python: Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 TIA Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
Phil Thompson wrote: On Sunday 23 September 2007, stef mientki wrote: Diez B. Roggisch wrote: stef mientki schrieb: Thomas Dybdahl Ahle wrote: Den Sun, 23 Sep 2007 17:28:38 +0200 skrev stef mientki: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? The best is Delphi, second is VB, That sounds mostly like a personal preference :) Well I prefer Python ( because of it's OS-independancy and it's open source), but Python is really (still) much worse for GUI designs. Just compare some parameters like: - ease of use - speed of development - support of features - availability of libraries - documentation Sounds like PyQt for me. Best GUI-designer I know, tremendous speed in development, giant sized lib that does all kinds of stuff is brilliantly designed + professional grade docus. Could well be, but I never looked at PyQt seriously, because of their weird license. It's not weird. It's either GPL or proprietary. Your choice. That's as complicated as it gets. This is what I find weird: == quote == Trolltech's commercial license terms do not allow you to start developing proprietary software using the Open Source edition. == end quote == Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: Properties and Objects...
En Sat, 22 Sep 2007 15:06:38 -0300, George V. Neville-Neil [EMAIL PROTECTED] escribi�: I have been trying to switch this over to using properties, which seem at first glance to be cleaner, but which I am having a lot of problems with. In particular I want to add a property to an object, not a class. The field list in a class is actually relatively static but I wind up with ugly code like: class ethernet(pcs.Packet): Ethernet __layout__ = pcs.Layout() _map = ethernet_map.map src = pcs.StringField(src, 48) dst = pcs.StringField(dst, 48) type = pcs.Field(type, 16) def __init__(self, bytes = None, timestamp = None): initialize an ethernet packet src = pcs.StringField(src, 48) dst = pcs.StringField(dst, 48) type = pcs.Field(type, 16) pcs.Packet.__init__(self, [dst, src, type], bytes = bytes) self.description = inspect.getdoc(self) You don't have to repeat the fields: pcs.Packet.__init__(self, [self.dst, self.src, self.type], bytes = bytes) does the same thing. And you can remove self.description=... and use (at the class level): description = __doc__ or: description = property(lambda self: self.__doc__) to automatically enable subclases to share the definition One could say that the field order is important so I'd finally write it as: class ethernet(pcs.Packet): Ethernet __layout__ = pcs.Layout() _map = ethernet_map.map src = pcs.StringField(src, 48) dst = pcs.StringField(dst, 48) type = pcs.Field(type, 16) _fields = [dst, src, type] description = property(lambda self: self.__doc__) def __init__(self, bytes = None, timestamp = None): initialize an ethernet packet pcs.Packet.__init__(self, self._fields, bytes = bytes) and assigning the properties at class time means that it's hard to have variations, packets with the same name but with slightly varying field lists. This is the part I don't understand. Can't you define a new class, in case you want a different field list? Using the above class: class ethernet_modified(ethernet): Modified ethernet class added_field = pcs.StringField(whatever, 16) _fields = [dst, src, type, added_field] And it doesn't even requiere an __init__ method So, is there a way to assign a property to an object, like this: def __init__( self.src = property() or something like that? I'd use different classes for different kind of objects. And, failing that, is there a clean way to modify the class in it's __init__() method so I don't have to call the Field objects twice, once for the property effect and once to put into the list in the base Packet class? I think my example above does what you want. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behavious of the logging module?
En Sun, 23 Sep 2007 18:53:53 -0300, Christian Meesters [EMAIL PROTECTED] escribi�: import logging logging.basicConfig(level=logging.ERROR, format='%(levelname)-8s %(message)s', filename='mc_rigid.log', filemode='w') # define a Handler which writes INFO messages or higher to the sys.stderr console = logging.StreamHandler() console.setLevel(logging.INFO) # set a format which is simpler for console use formatter = logging.Formatter('%(message)s') # tell the handler to use this format console.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(console) I observe nothing printed on the console. However if I change the level (just after the import) from logging.ERROR to logging.DEBUG I do see all info lines on the console as intended. basicConfig sets the root logger level; if it's ERROR, nothing below ERROR will pass. Your handler does not have a chance to get the message. Can anybody tell my mistake? I thought changing the level in basicConfig would have no impact on the following StreamHandler instance. basicConfig sets the overall verbosity of your application. Also, adding %(funcName)-8s to the formatter in basigConfig does not work for me: instead of the functions name the level in lower case gets inserted into the logfile. Looks like a bug... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
SimPy, audio interview with creators of
SimpPy is a powerful simulation package for Python. I have just posted an interview (podcast) with Dr. Klaus Muller in Amsterdam and Professor Tony Vignaux in New Zealand about their creation, SimPY, an object-oriented, process-based discrete-event simulation language based on standard Python. Check it out at www.awaretek.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Cristian a écrit : (snip) To me, the biggest setback for new programmers is the different syntax Python has for creating functions. Instead of the common (and easy to grasp) syntax of foo = bar It's actually a mostly *un*common syntax when it comes to functions. The only mainstream language I know allowing such a syntax is javascript. Now given python's parsing rules, I wonder how this could be implemented... Python has the def foo(): syntax. So, when a new programmer is first introduced to functions they are immediately confronted with the notion that functions are different. Which is the case in most non functional languages. After all, they have their own special syntax. This seems to only further the separation newbies make between data and functions or stuff and actions. Now, the vast majority of us learned this dichotomy when we first began to program, so we are ingrained to assume and even expect a different syntax for function declaration, but in a program like Python there doesn't seem to be any other reason to have it. Technically, I'd say patsing rules. From a more conceptual POV, Python was meant to be the missing link between shell scripts and C - and some design choices clearly (IMHO) came from the desire to look familiar enough to C programmers. Even if Python ended up with some (restricted) support for functional programming, it's still has it's roots in procedural programming. Furthermore, I think it actually inhibits the learning of the uninitiated. We can, of course, keep the current syntax as sugar. To someone who's learning to program wouldn't a syntax like the further give them all they need and also reinforces the idea that functions are data just like everything else? Python's functions are *objects* like anything else. And objects are more than data. My 2 cents: show your friend that Python's functions are objects, and that other objects can be callable too... my_function = function(foo, bar): pass an_instance_method = function(self, foo): pass a_method_declaration = method(self, foo): pass The last one is mostly my pet peeve of having Python magically create methods out of (what is essentially) a function declaration. There's not much magic in this. What's stored as an attribute of the class *is* a function. It's only wrapped in a method object when looked up. And FWIW, it's the function object itself that takes care of this, thanks to the descriptor protocol (all relevant doc is on python.org). When I first learned it, it felt wrong but you had to press through it because there was really no other way of declaring methods. Truth is that you do *not* declare methods in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Kay Schluehr a écrit : (snip) I checked out Io once and I disliked it. I expected Io's prototype OO being just a more flexible variant of class based OO but Io couples a prototype very closely to its offspring. When A produces B and A.f is modified after production of B also B.f is modified. A controls the state of B during the whole lifetime of B. I think parents shall not do this, not in real life and also not in programming language semantics. I may totally miss the point, but how is this different from: class A(object): def dothis(self): print A.dothis(%s) % self class B(A): pass b = B() b.dothis() def dothat(self): print function dothat(%s) % self A.dothis = dothat b.dothis() -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Kay Schluehr a écrit : On 22 Sep., 23:17, Erik Max Francis [EMAIL PROTECTED] wrote: The attribute and method (not made distinct in Io; they're called slots) is much the same as with Python; the current instance is checked for the object, then its parents, then _its_ parents, and so on. Repeating the same point as Marc doesn't mean that I have to repeat my reply as well. Doesn't it? Then please don't answer my own repeating of the same point !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Cristian a écrit : On Sep 21, 4:47 pm, Sean Tierney [EMAIL PROTECTED] wrote: Just tell him that functions are like all other variables and can therefore be passed by other functions or returned by other functions. I could Just tell him that functions are like all other variables and can therefore be passed by other functions or returned by other functions. but wouldn't it be great if Python did this for me? It seems to me that the ability for Python to explicitly state that functions-are- like-other-variables is there so why not expose it? Ok, then what about classes ? They also are objects-like-any-other, after all. So should we have this syntax too ? MyClass = class(ParentClass): __init__ = function (self, name): self.name = name ?-) -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
On Mon Sep 24 00:08:09 CEST 2007, stef mientki wrote: Phil Thompson wrote: On Sunday 23 September 2007, stef mientki wrote: Could well be, but I never looked at PyQt seriously, because of their weird license. It's not weird. It's either GPL or proprietary. Your choice. That's as complicated as it gets. This is what I find weird: == quote == Trolltech's commercial license terms do not allow you to start developing proprietary software using the Open Source edition. == end quote == Well, if you know you're going to be developing proprietary software, what on earth are you doing with the Open Source edition? OK, perhaps by asking that rhetorical question I'm simplifying people's reasons and motives for using Open Source (and in this case Free/Libre) software to develop tools or solutions that they later want to release as closed, proprietary products. There are lots of ways people can end up in that position, of course. Some people find their way there by accident; others know what the situation is going to be well in advance... In any case, I think it's useful to be clear about what each license does or does not allow, especially if this leads to people making informed decisions well before they learn about the consequences. In this case, the terms of the commercial license place certain demands on the licensee, just as with many other commercial licenses. If someone develops a product using a GPL-licensed library, they can always release that product under the GPL, even if that's not what they had in mind when they started. ;-) David -- http://mail.python.org/mailman/listinfo/python-list
http://www.agloco.com/r/BBFR2592
http://kgsm.websitesiekle.com/ Thanks 1. Hi everyone, For all of you that are asking for caculations for how much pay, just consider this. There is truly no way anyone can calculate with all variables. The pay is dependent upon the advertisers paying agloco, the search engines paying agloco, the merchants paying agloco the commissions on the sales to agloco members, and any other sources of income. This money all goes into a pool, of which agloco management gets 10% and the rest is divided among the owners/members. There you have it. income is variable, percentages for management and the owners ia fixed. membership is variable. These variable parts will change by the minute. No reasonable mathmatician will attempt to arrive at meaningful calculations with two massive variables and one fixed quantity. All the mathmatician can do at this point is offer statistical possibilities. In the short view, every person you sponsor now cuts down on the value of the cash pool individually. In the longer term, more members means agloco can charge more for the ads and make the cash pool larger. As far as clicking the ads, That will create cash pool money when the few make purchases and the merchant pays agloco the commission on the sale. In at least some cases, the member will immediately benefit from any discounts that are given to the agloco membership. Regards searches, I do not know what deal agloco has with google or the other search engines at this time, but I do know that as the membership goes up, so does the price google and the others will pay agloco for each search performed. Google currently pays aol 10 cents per search performed. Best I can tell you is the per hour pay will fall into a range somewhere between .1 cents and 1,000.00 dollars per hour.( both top and bottom values estimated with the fact that everyone is so desparate for promises that poor Brian cannot say anything without it being considered a set in concrete promise.) I intentionally used extremes. Try to keep your shirt on and wait and see what materializes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing Object Data to Disk
Amit Kumar Saha wrote: Actually, language independence is really not a consideration here. I am happy at having it tied to Python :-) BTW, do we have something like array of objects here? In numpy, one can have a multi-dimensional array of objects. It would be good to have this notion implemented in Python itself. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: __contains__() and overload of in : Bug or Feature ???
[EMAIL PROTECTED] wrote: Thanks for your quick response. I need to overload the operator in and let him return an object ... It seems it is not a behavior Python expect : class A: ...def __contains__(self,a): ...return 'yop' ... a=A() print 'toto' in a True print a.__contains__('toto') yop Not sure what you're trying to achieve, Using Python as an algebraic parser for symbolic mathematical equation and I need that the 'in' operator returns an object based on its two arguments. but the semantics of the in operator make it return a boolean value. That is why I need to overload it. The string yop evaluates to the boolean value True, as it is not empty. Does it means that when overloading an operator, python just wrap the call to the method and keep control of the returned values ??? Is there a way to bypass this wrapping ??? Can you not achieve what you wish to do with a conditional expression? yop if a in b else nop Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
Scott David Daniels wrote: Ron Adam wrote: Scott David Daniels wrote: Ron Adam wrote: How about this? def integrate(fn, x1, x2, n=100):... The point was a pedagogic suggestion, ... I understood your point. I just found it interesting since I've been trying to extend my math (for use with python) skills in this area. Ah, sorry. I had realized I wasn't explicit in my first message. Yes, I wasn't trying to correct you. I'm sorry if it came across that way. Yes, a perfectly fine integration. There's still something about it that bothers me. I think it may be the n=100 rather than delta='.0001', or some other way to specify the minimal error. (Yes, it's a bit off topic.) You can then (and this is a major jump to get used to): import functools Sine = functools.partial(integrate, math.cos, 0.0, n=100) I haven't played around with .partial yet. I wonder if it could be used in dispatching situations where the function signatures differ? Similarly, you can define a derivative that will behave fairly well, all without examining the definition of the function being operated upon. I'll get around to doing that at some point. ;-) I also have a class that solves equations that takes a function in a similar way. It uses the same method used by HP calculators to solve TVM equations. Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
On 2007-09-23, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Sep 23, 4:28 pm, stef mientki [EMAIL PROTECTED] wrote: yadin wrote: if i were up to make a GUI chich are the advantages of choosing python over matlab or java? As MatLab has a very lousy GUI, any other language would be an advantage ;-) The best is Delphi, second is VB, then comes SciLab, Python, etc I don't know where Java fits in. But as Wildemar said, your question is much to broad. cheers, Stef Form a newbie's point of view, Java's Swing Libraries (gui stuff) are pretty easy to get to grips with, if a bit big. They are also incredibly well documented, and are distributed by sun with the core language. Since you can use Swing from Python, it seems a false dichotomoty to choose between Java and Python based on how well you like Swing. [I've never used Swing from Python -- I don't have very heavyweight computers and try to avoid anything Java-related.] Though you can probably find more Swing examples in Java than in Python -- Grant Edwards grante Yow! Well, I'm INVISIBLE at AGAIN... I might as well visi.compay a visit to the LADIES ROOM... -- http://mail.python.org/mailman/listinfo/python-list
Re: TRying to import files from my folder not pythons lib folder
Steve Holden wrote: [EMAIL PROTECTED] wrote: On Sep 21, 12:32 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I'm trying to create my own lib of functions, but it seems like I can only import them if they are in pythons lib folder. Example I have a folder called K:\mypython Now in the interactive python shell I type Import k:\mypython\listall And get a error on : If I store listall.py in pythons lib folder and type Limport listall It works fins. Can I create my own library of functions and store them in a separate dir Also I try to creat a folder in pythomns lib folder and that did not work Help -Ted One workaround is to do to this: code import sys sys.path.append(r'K:\mypython') import listall /code You can also add your path to the .pth file, but I've never done that, so I can't tell you how. Hope that helps! Mike The easiest way, particularly for testing, is to set the PYTHONPATH variable. It should be a colon-separated list of directories on Unices, and a semi-colon separated list on Windows. Those directories will be added to sys.path. See http://docs.python.org/tut/node8.html for yet more. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline This is exactly what I did, but I have a new problem now: After seting PYTHONPATH I'm no longer able to start IDLE from the start menu. It seems the system cannot find the file. But if I eliminate PYTHONPATH, everything works as it used to. I set PYTHONPATH because I wanted to import any existing file in my desktop without having to use sys.path.append... It works when using the command line but strangely, something get messed up with IDLE. Any hint? Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
On 22 Sep., 02:14, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Kay Schluehr a écrit : (snip) I checked out Io once and I disliked it. I expected Io's prototype OO being just a more flexible variant of class based OO but Io couples a prototype very closely to its offspring. When A produces B and A.f is modified after production of B also B.f is modified. A controls the state of B during the whole lifetime of B. I think parents shall not do this, not in real life and also not in programming language semantics. I may totally miss the point, but how is this different from: class A(object): def dothis(self): print A.dothis(%s) % self class B(A): pass b = B() b.dothis() def dothat(self): print function dothat(%s) % self A.dothis = dothat b.dothis() It's not a big deal because you do not use a class to propagate mutable state unless you are using a class attribute intentionally ( i guess you do not overuse it just to avoid object encapsulation and make everything global ). When using a prototype as in Io you need to protect the state of the child object yourself. You can do this by overwriting the objects slots but then you end up writing your own object constructors and the templates accordingly, also named classes by some. Not having dedicated object constructors, member variable initializations and the presumed class definition boilerplate comes at the price of introducing them on your own. Prototypes have a purpose of course when you want to transfer state to a newly created object. Using a prototyping mechanism as a generic form of a copy constructor is the right kind to thinking about them IMO. I have got the impression that the discussion has drifted away from what Paul Rubin suggested, namely abandone the expression/statement distinction. Instead we are discussing the advantages and disadvantages of object models now. Can we stop here, please? -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting rid of bitwise operators in Python 3?
[EMAIL PROTECTED] wrote: On Sep 22, 7:04 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Sat, 22 Sep 2007 21:17:38 +, Bryan Olson wrote: The operator module offers pow(). Is there any good reason for pow() as a built-in? The `operator.pow()` is just the function for ``**``, it lacks the optional third argument of the built in `pow()`. Ciao, Marc 'BlackJack' Rintsch But does the three-argument version of pow() really belong in the core? Who uses it? It was a common cryptographic operation. The two-argument version is used by the same person who wrote the semi-colon at the end of every line of the code I'm working with. Personally, I'm sorry that 'and' and 'or' weren't chosen for the bitwise operators: I'd happily give up 'and' and 'or' for logic operations. [david] -- http://mail.python.org/mailman/listinfo/python-list
Re: Preemption in python
Thanks a ton! Just for the eventual webcrawler that logs this, the gtk package requires a separate thread init function to allow python threads to play nice. On 9/23/07, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 23 Sep 2007 16:10:03 -0300, Kurtis Heimerl [EMAIL PROTECTED] escribi�: I'll explain a bit more. This thread is spawned, I also have the main thread running a gtk windowed gui. The gui has it's own threads to deal with button presses and such. The problem is that the gui never seems to let anyone else run. Only on button presses that cause blocking calls ( ossaudiodev.audio.read for instance) does the reader thread print anything. Google for python gtk threading tutorial -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: An Editor that Skips to the End of a Def
In message [EMAIL PROTECTED], Manuel Graune wrote: Matthew Woodcraft [EMAIL PROTECTED] writes: Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: http://www.asktog.com/SunWorldColumns/S02KeyboardVMouse3.html And cursor keys? Please, every self respecting editor has ways for moving around quite a bit more efficiently. And on top of that a use case, which no one in his right mind would do this way. Accomplishing this task with search-and-replace would have taken about 10 seconds. With Mouse or Keyboard. Just to reinforce the point that the above was in no way an artificial or isolated case: http://www.asktog.com/TOI/toi06KeyboardVMouse1.html http://www.asktog.com/TOI/toi22KeyboardVMouse2.html -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess -popen - reading stdout from child - hangs
In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Let's say I have this Python file called loop.py: import sys print 'hi' sys.stdout.flush() while 1: pass And I want to call it from another Python process and read the value 'hi'. How would I do it? So far I have tried this: proc = subprocess.Popen('python /home/chiefinnovator/loop.py',shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE) proc.stdout.read() But it just hangs at read() That's because you didn't tell it how much to read, so by default it tries to read until EOF http://docs.python.org/lib/bltin-file-objects.html. But since the subprocess is still running and hasn't closed its stdout, the pipe has not reached EOF. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Bulk] Re: Writing Object Data to Disk
In message [EMAIL PROTECTED], Amit Kumar Saha wrote: I appreciate the XML related comment, but as of now I am ready-to-roll with Python specific pickling. XML will be used in a later version of my code! Will you need to maintain backward compatibility with data written by the current version of your code? -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess -popen - reading stdout from child - hangs
In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Well, using this subclass of subprocess.Popen fixes the problem (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554) I don't understand how it works though. Would anyone mind explaining? I'm thinking there's something fundamental about Unix processes I'm not understanding. The select calls are checking that the subprocess is ready to read before writing to its stdin, or that it has something to write before reading from its stdout. The O_NONBLOCK fcntl simply says not to wait if there is nothing more to be read, just return what was already read. -- http://mail.python.org/mailman/listinfo/python-list
Re: Would Anonymous Functions Help in Learning Programming/Python?
On Sep 21, 5:21 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Ok, then what about classes ? They also are objects-like-any-other, after all. So should we have this syntax too ? MyClass = class(ParentClass): __init__ = function (self, name): self.name = name ?-) For consistency I would suggest this, but Python already does this! Foo = type('Foo', (object, ), {'bar': lambda self, bar: bar}) I've created a new class and then binded it to name afterwards. If you can import modules without special syntax and you can create classes without special syntax, why should functions be treated any differently? -- http://mail.python.org/mailman/listinfo/python-list
Re: database persistence with mysql, sqlite
In message [EMAIL PROTECTED], coldpizza wrote: So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1 and L2 define the range for the 'Next' and 'Previous' commands. I have to run the query every time a click a 'Next/Prev' link. But I am not sure that this is the best and most efficient way. Try it first, then see what happens. Remember, premature optimization is the root of all (programming) evil. -- http://mail.python.org/mailman/listinfo/python-list
Database Abstraction Layer And/Or ORM
Hello all, I am looking for opinions on preferred methods of Database Abstraction Layer or Object Relation Mapper (I'm using Python 2.5). I have found a number of options such as those listed here: http://wiki.python.org/moin/HigherLevelDatabaseProgramming I'm not looking for a holy war based on whether a DAL/ORM *should* be used, and/or if it is preferred over direct access to the database API layer. I understand that can be a lengthy discussion. I would just like to see if there is a common 'preferred choice' in the area. I am coding an application around SQLite, but need to keep the flexibility to allow the use of MySQL (or other). Thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie completely confused
In message [EMAIL PROTECTED], Gabriel Genellina wrote: En Fri, 21 Sep 2007 13:34:40 -0300, Jeroen Hegeman [EMAIL PROTECTED] escribi�: class ModerateClass: def __init__(self): return def __del__(self): pass return class HugeClass: def __init__(self,line): self.clear() self.input(line) return def __del__(self): del self.B4v return def clear(self): self.long_classes = {} self.B4v={} return (BTW, all those return statements are redundant and useless) The OP could be trying to use them as some kind of textual indicator of the end of the function. Myself, I prefer end-comments, e.g. class HugeClass : ... def clear(self) : ... #end clear #end HugeClass -- http://mail.python.org/mailman/listinfo/python-list
Re: building a GUI
In message [EMAIL PROTECTED], stef mientki wrote: ... I never looked at PyQt seriously, because of their weird license. What's weird about it? Lots of software products are dual-licensed, e.g. MySQL, Perl. -- http://mail.python.org/mailman/listinfo/python-list
RE: I could use some help making this Python code run faster usingonly Python code.
Python Maniac wrote: Some benchmarks showing the effectiveness of using Psyco: scramble: 4.210 scramble_listcomp: 2.343 scramble_gencomp: 2.599 scramble_map: 1.960 scramble_imap: 2.231 scramble_dict: 2.387 scramble_dict_map: 0.535 scramble_dict_imap: 0.726 scramble_translate: 0.010 Now with Psyco... psyco.bind(scramble)... scramble: 0.121 4.088 34.670x faster scramble_listcomp: 0.215 2.128 10.919x faster scramble_gencomp: 2.563 0.036 1.014x faster scramble_map: 2.002 -0.043 0.979x slower scramble_imap: 2.175 0.056 1.026x faster scramble_dict: 0.199 2.188 11.983x faster scramble_dict_map: 0.505 0.029 1.058x faster scramble_dict_imap: 0.728 -0.001 0.998x slower scramble_translate: 0.009 0.001 1.111x faster Overall, Psyco helped my little process of converting 20 MB worth of ASCII into what may not look like the original at 6x faster than without Psyco. One thing you should notice with the above results: Psyco made your initial, totally unoptimised algorithm the fastest of all (except for translate, which is in a different league of course - but is much more limited in what it can do). The other algorithms are already heavily working in C code (dicts, etc), but the initial algorithm provided lots of opportunities for Psyco to hook in and use the runtime behaviour. So, before trying to optimise, see if Psyco gives you the performance you need. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
[issue1064] Test issue
Martin v. Löwis added the comment: Compare From headers -- assignee: georg.brandl - nosy: -georg.brandl __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1064 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1727780] 64/32-bit issue when unpickling random.Random
Changes by Martin v. Löwis: -- assignee: - loewis severity: normal - major _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1727780 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1130] Idle - Save (buffer) - closes IDLE and does not save file (Windows XP)
New submission from Tal Einat: The saving bug is a string/bytes issue, simply fixed by replaced line 366 in Lib\idlelib\IOBinding.py with: chars = chars.replace(b\n, self.eol_convention.encode('ASCII')) -- nosy: +taleinat __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1130 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1182] Paticular decimal mod operation wrongly output NaN.
Hirokazu Yamamoto added the comment: I tracked down, and I noticed following code was invoked. Lib/decimal.py (release-maint25 Decimal#_rescale) 1912: if watchexp and digits context.prec: 1913: return context._raise_error(InvalidOperation, 'Rescale prec') from decimal import * d = Decimal(23.08589694291355371979265447) print d % Decimal(2.302585092994045640179914546844) # NaN print Decimal(0.060046012973097317993509001560)._rescale(-30) # error Length of decimal seems to be important, so I changed length and it seemed working. print d % Decimal(2.302585092994045640179914547) # 0.060046012973097317993509000 Maybe is this intended behavior? Still I feel 2.6's behavior is less suprising though... __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1182 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1160] Medium size regexp crashes python
Fredrik Lundh added the comment: Well, I'm not sure 81k qualifies as medium sized, really. If you look at the size distribution for typical RE:s (which are usually handwritten, not machine generated), that's one or two orders of magnitude larger than medium. (And even if this was guaranteed to work on all Python builds, my guess is that performance would be pretty bad compared to a using a minimal RE and checking potential matches against a set. The | operator is mostly O(N), not O(1).) As for fixing this, the byte code used by the RE engine uses a word size equal to the Unicode character size (sizeof(Py_UNICODE)) for the given platform. I don't think it would be that hard to set it to 32 bits also on platforms using 16-bit Unicode characters (if anyone would like to experiment, just set SRE_CODE to unsigned long in sre.h and see what happens when you run the test suite). __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1160 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1192] Python 3 documents crash Firefox
New submission from Robert T McQuaid: I downloaded python-3.0a1.msi for Windows XP and after install converted the documentation from chm format to html with the hh.exe utility in XP. The resulting files crashed Firefox version 2.0 (it slowly chokes to death in a dozen operations), but worked fine on Opera 9.21. -- components: Documentation messages: 56099 nosy: rtmq severity: minor status: open title: Python 3 documents crash Firefox type: behavior versions: Python 3.0 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1192 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1192] Python 3 documents crash Firefox
Martin v. Löwis added the comment: Why do you think this is a bug in Python? If Firefox crashes, isn't this rather a bug in Firefox? Please report it at bugzilla.mozilla.com. Closing as third-party bug. -- nosy: +loewis resolution: - invalid status: open - closed versions: +3rd party -Python 3.0 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1192 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1193] os.system() encoding bug on Windows
New submission from Fan Decheng: Python 3.0 uses utf-8 encoding, but os.system() when running on Windows uses the system default encoding, which may be cp936 or mbcs. They are incompatible. -- components: Library (Lib) messages: 56101 nosy: r_mosaic severity: major status: open title: os.system() encoding bug on Windows type: behavior versions: Python 3.0 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1193 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com