Re: Dabo in 30 seconds?
On Sat, 2005-07-30 at 20:29 -0700, James Stroud wrote: I am going to go ahead and throw out Dabo with all of the others that claim quick development of an application. You try them and then you get bugs, bugs, bugs. Or they don't compile without 16000 dependencies. Forget it. My advice is to choose something, one thing, that is REAL standard, and in the standard library (e.g. Tkinter). And go for it. Learn it inside and out--it will always be there for you. It is the green, green grass of home, not that greener grass on the other side of the hill. Don't listen to the guys that says this one is crap or that one isn't. Dropping one and learning another is just pain. I think this is a developer trick, to keep you at war with yourself. The more you have internal conflict the more you will be looking for an App framework to solve your inner problems, and that keeps these guys in business--the business of wrecking souls. Then why are you using Python at all? Shouldn't you be in the safe home of Java or Visual Basic, where standards are all you have? -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: [path-PEP] Path inherits from basestring again
On Sat, 30 Jul 2005 19:01:49 +0200, Reinhold Birkenfeld [EMAIL PROTECTED] wrote: phil hunt wrote: def normalizePath(p, *pathParts): Normalize a file path, by expanding the user name and getting the absolute path.. @param p [string] = a path to a file or directory @param pathParts [list of string] = optional path parts @return [string] = the same path, normalized p1 = os.path.abspath(os.path.expanduser(p)) if len(pathParts)0: allPathParts = [ p1 ] allPathParts.extend(pathParts) p1 = os.path.join(*allPathParts) p2 = os.path.abspath(p1) return p2 normalisePath=normalizePath # alternate spelling join=normalizePath # it works like os.path.join, but better To be honest I don't see the point of having a Path class. That's the way Java does it, and I find path handling in Java to be a lot more of a hassle than in Python. (Actually, most things are more of a hassle in Java, but that's another story). You see, with the Path class the above function could be written as def normalizePath(p, *pathParts): Normalize a file path, by expanding the user name and getting the absolute path.. @param p [Path] = a path to a file or directory @param pathParts [list of string/Path] = optional path parts @return [Path] = the same path, normalized tp = p.expanduser().abspath() return tp.joinwith(*pathParts).abspath() That's clearly an improvement, isn't it? An improvement to what? To how the class is implemented, or to how it is used? If you mean the former, yes is it, due to the os.path module not providing a function that does this. If you mean the latter, I disagree, because I would then have to call it with something like: pn = normalizePath(Path(p), q) and then I would have the problem that (pn) isn't a string so calling a function to write some data into the file at that filename would no longer work, i.e. this: writeFile(pn, someData) would become this: writeFile(pn.getString(), someData) I don't see what having a Path type buys me. -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sat, 30 Jul 2005 16:51:13 +0200, Torsten Bronger [EMAIL PROTECTED] wrote: Hallöchen! [EMAIL PROTECTED] (phil hunt) writes: [...] How about sometihing with the same API as Tkinter (so no need to relearn), but which looks prettier? Would that fix your gripes? I haven't learned Tkinter. You mightn't have, but I suspect more Python programers who've written GUI apps have used Tkinter than any of the other APIs. Not that I'm a particular fan of it, it's just I like standardisation, because then you get network effects. So for me, it needn't be like Tkinter. The three most important attributes for me are Pythonic, modern (both nice-looking and comprehensive), and non-niche. What you say Pythonic, what do you mean? And how do you rate Tkinter, PyGtk, PyQt/PyKDE, wxWindows for Pythonicness? -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
On 30 Jul 2005 17:48:39 -0700, Paul Rubin http://[EMAIL PROTECTED] wrote: Shelve uses dbm and pickle to make a persistent object store. The db in dbm stands for database and while I didn't expect full ACID capability, What is ACID? I'd have thought there'd be at least some minimum gesture towards durability of updates. But say that s is a shelve object. If I say s[whatever] = value there is no way apparent from the shelve docs to get the update flushed out to the disk file until the shelve is actually closed. Wierd. I'd expect something like an s.flush() function. -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
On Sat, 30 Jul 2005 17:57:17 -0700, Robert Kern [EMAIL PROTECTED] wrote: Paul Rubin wrote: Shelve uses dbm and pickle to make a persistent object store. The db in dbm stands for database and while I didn't expect full ACID capability, I'd have thought there'd be at least some minimum gesture towards durability of updates. But say that s is a shelve object. If I say s[whatever] = value there is no way apparent from the shelve docs to get the update flushed out to the disk file until the shelve is actually closed. If I'm using the shelve to store stuff in a long-running server, it could be months before the shelve closes. Is shelve really missing this capability? No. Call the .sync() method. Unfortunately, the shelve module is not well-documented. Obviously it's good when stuff is well documented. I wonder if the barrier to good documentation is set too high? If i wanted to add some documentation here, I'd have to download the current source for the latest Python documentation, download, install and learn the code that processes the source documentation, write my changes then send the results into the CVS. (I'm assuming that's roughly correct -- I haven't actually done it). The point is, that would be a major effort, too major to merely add a few lines detailing the .sync method. But, what if the Python documentation was on a Wiki? Then it would be easy to update! Of course, we would have to guard against false or malicious updates, but Wikipedia manage that OK. The Documentation Wiki could then be used as a basis for the official documentation that comes with each new release. Does this idea make some sense? Or are there hidden pitfalls? -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Hallöchen! [EMAIL PROTECTED] (phil hunt) writes: On Sat, 30 Jul 2005 16:51:13 +0200, Torsten Bronger [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (phil hunt) writes: [...] How about sometihing with the same API as Tkinter (so no need to relearn), but which looks prettier? Would that fix your gripes? I haven't learned Tkinter. [...] Not that I'm a particular fan of it, it's just I like standardisation, because then you get network effects. Me too. Therefore I'd like to see a new toolkit in the standard library to see a new network growing. You mustn't do something like this too often of course but I think in this case it would be the right time. So for me, it needn't be like Tkinter. The three most important attributes for me are Pythonic, modern (both nice-looking and comprehensive), and non-niche. What you say Pythonic, what do you mean? And how do you rate Tkinter, PyGtk, PyQt/PyKDE, wxWindows for Pythonicness? I don't like to set arguments to -1 or NULL, but to None. I'd like to have extensive support for keyword arguments. I don't like mucking about with ID values. Partly this is cosmetical but partly it's a rich source of errors. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 00:59 -0400, Mike Meyer wrote: I don't particularly like Tkinter, but it seems to me that it's pretty much won. It seems to be installed on every desktop platform along with Python. That means that if I want to distribute GUI apps, I'm going to cause the least headache for my end users by writing them in Tkinter. By this argument, we should just give up and use Visual* on Windows. The least headache for end users comes from properly packaging your application. End users shouldn't need to worry about installing third party packages (or even Python for that matter). Tools such as py2exe and Inno installer make this pretty simple on Windows, and py2app on OS/X accomplishes the same. It should be irrelevant to end users what libraries or tools you use to develop the app. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: The state of OO wrappers on top of wxPython (was Re: Wheel-reinvention with Python)
On Sat, 2005-07-30 at 16:52 -0700, Bugs wrote: Cliff Wells wrote: But how stable is GTK on systems such as Windows and OS/X? That has been what has kept me from using it. Most GTK apps I've used on Windows (including the venerable GIMP) are nowhere near as stable as their Linux counterparts (although this may not be entirely the fault of GTK). Also, GTK on OS/X requires Fink, which is a pretty hefty requirement to place on an end user. wxWidgets only uses GTK on Linux. On Windows and OS X it uses native widgets where possible. You missed my point. I'm advocating wxPython over PyGTK for this reason. I'm quite aware of how wxPython functions. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
phil hunt wrote: Obviously it's good when stuff is well documented. I wonder if the barrier to good documentation is set too high? If i wanted to add some documentation here, I'd have to download the current source for the latest Python documentation, download, install and learn the code that processes the source documentation, write my changes then send the results into the CVS. (I'm assuming that's roughly correct -- I haven't actually done it). No, write the content in a reasonable format (i.e. plain text), post it to the bug tracker, assign it to Fred Drake (I think), and he'll put it in the right format. If it's longer documentation, like for a full module, then it's better to actually learn the LaTeX so it can be dropped in as is. The point is, that would be a major effort, too major to merely add a few lines detailing the .sync method. But, what if the Python documentation was on a Wiki? Then it would be easy to update! Of course, we would have to guard against false or malicious updates, but Wikipedia manage that OK. That's a debatable assertion, but I don't think we'll have the same problems of Wikipedia thanks to the apolitical nature of Python documentation. The Documentation Wiki could then be used as a basis for the official documentation that comes with each new release. Does this idea make some sense? Or are there hidden pitfalls? Yes! Someone actually has to do it! The same idea has come up time and time again. It's still not here because no one has been able to commit to the effort involved. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Error
The message cannot be represented in 7-bit ASCII encoding and has been sent as a binary attachment. -- Virus Warning Message (on cse.iitkgp.ernet.in) file.bat is removed from here because it contains a virus. --- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
[EMAIL PROTECTED] (phil hunt) writes: No. Call the .sync() method. Unfortunately, the shelve module is not well-documented. Obviously it's good when stuff is well documented. I wonder if the barrier to good documentation is set too high? If i wanted to add some documentation here, ... I entered a sourceforge bug asking that the doc be updated (thanks, Robert!). I've done that several times before for similar small doc bugs and they've always been taken care of reasonably quickly. There's a documentation category in the bug reporting template for this purpose. -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
[EMAIL PROTECTED] (phil hunt) writes: What is ACID? Basically it means full-blown a transactional database that handles concurrent updates correctly. See: http://en.wikipedia.org/wiki/ACID Wierd. I'd expect something like an s.flush() function. Thanks to Robert Kern for pointing out that the answer is s.sync(). -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
[EMAIL PROTECTED] (phil hunt) writes: What you say Pythonic, what do you mean? And how do you rate Tkinter, PyGtk, PyQt/PyKDE, wxWindows for Pythonicness? Tkinter is not very Pythonic because it's sort of a Frankenstein hybrid of Python and Tcl, but at least it's there and it more or less works. The others are non-Pythonic because they're not included in the standard distro and therefore the Pythonic use the included batteries tenet says to use Tkinter despite its flaws. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a string like '777' to an octal integer like 0777?
Thanks, John. But my point is how to keep the leading zero in 0777, in order to be used in os.chmod('myfile', 0777)? -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP on path module for standard library
Peter Hansen wrote: A scattered assortment of module-level global function names, and builtins such as open(), make it extraordinarily difficult to do effective and efficient automated testing with mock objects. I have been able to do this by inserting my own module-scope function that intercepts the lookup before it gets to builtins. A problem though is that a future (Python 3K?) Python may not allow that. For example, module.open = mock_open try: ... finally: module.open = open By looking at the call stack it is possible to replace the built-in open to have new behavior only when called from specific modules or functions, but that gets to be rather hairy. Object-oriented solutions like Path make it near trivial to substitute a mock or other specialized object which (duck typing) acts like a Path except perhaps for actually writing the file to disk, or whatever other difference you like. By analogy to the other builtins, another solution is to have a protocol by which open() dispatches to an instance defined method. So, for the PEP, another justification for Path is that its use can encourage better use of automated testing techniques and thereby improve the quality of Python software, including in the standard library. But then what does the constructor for the file object take? I've also heard mention that a future (Py3K era) 'open' may allow URLs and not just a path string. Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Thaughts from an (almost) Lurker.
Sometimes when reading c.l.p. I mentally stand off from what I have been reading and get an odd feeling that 'WE ARE BEING TESTED'. That someone else is purposefully posting a near repetitive post, or obvious flame bait etc - not for the usual reasons, but to track the dynamics af the replies. Rather like dropping a stone in the river and watching pythonistas return c.l.p. to its normal, helpful, and polite norm. Fascinating. I only hope that if thats the case, then they should post their findings here. - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re[2]: 2-player game, client and server at localhost
Thank you very much for your response, and may I point out some details: It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client has 5, and due to forced synchronization, they both run very slowly (I wonder how come server says it has 44fps?). DLB Well, for a 2 player game of this sort, I'd think there should DLB be one server and TWO clients... It sounds more like you have a DLB master-slave arrangement with the slave forced to synchronize to the DLB master. Yes, that's what I have. I was already told I should have 1 server and 2 clients, well I will, but I'd really like to make it work the master-slave way now. DLB If you are running on Windows, Yes, I am To answer the rest of your message: the client and server (C and S below) are actually equal in my implementation. They both compute everything. I was told it's not smart to do that, but I can't see why is it better to have server compute everything: there are only 2 players, and there's quite not much computations, while transferring current status is much more traffic-consuming than simply transferring user motions. Below I outline what S and C do: S: loop draw screen accept player1 input from mouse/kbd send player1 input to C process player1 input hang till C sends us player2 input process player2 input do the nasty computations :) end loop C: loop draw screen hang till S sends us player1 input process player1 input accept player2 input from mouse/kbd send player2 input to S process player2 input do the nasty computations :) end loop So you see C and S should cause equal load of CPU. By the way, yesterday a friend of mine kindly agreed to test the game online with me, and my God I was so happy to see it DID connected and we could play (yes, this is the first program in my 10+ years of programming that sends something over the web), but the speed is overwhelmingly dreadful, near 3 fps :), while my 1.2 Celeron said I had 21 fps, and his 3.0 Pentium said he had 120. He tends to think that my problem is that they both hang to wait for the input of each other, and that happens after each frame is drawn. Well, it is lame, but why does it work fine at my pc when client window is active? And another important note - he also tested 2 instances playing via localhost at his PC, and they both indeed had 35 fps, no matter which window was active. I believe he has hyperthreading turned on while I don't, but I wonder home come it wouldn't work without it? I've looked at my CPU load, and for C being active we have 45% for C/45% for S, while for S being active - 88% for S/ 11% for C :(( I'd really welcome any suggestions, please. DLB the program with the input focus is probably running at a higher DLB priority... So the server, when having input focus, gets to compute DLB lots of stuff while the client gets less CPU time... and if the DLB client then (whenever it does a frame say) does a transaction with DLB the server, it may do nothing while waiting for the DLB server to respond. DLB When the client has the focus, the server may be processing at DLB lower priority, and the two only seem to match speed because the client DLB is blocked waiting for a response from the server (allowing the server DLB to run at full speed until it sends the response). Does anybody have an idea how can this be? Not that users will test 2 game intances communicating via localhost, but I need to make it work properly. DLB Define work properly... It sounds like they are working DLB properly /as coded/ and are being affected by OS priority schemes. I DLB say as coded since, as I mentioned in the first paragraph, it sounds DLB like you have your server doing double duty -- both as a client and as DLB the server for the second client. The server should not have ANY client DLB type interface (other than start-up and shut-down or debug override DLB commands). All frame-based rendering should be in the clients. I also DLB suspect that, with two clients and a server, you'd see the same behavior DLB -- the non-input client will be running at a lower priority, thereby DLB achieving a lower frame-rate. DLB It also sounds like your server is doing something like: DLB loop DLB if socket has data then DLB read socket DLB compute new state DLB send reply DLB end if DLB do nasty computation DLB end loop DLB This logic will suck up as much CPU time as the OS will give the DLB program... While if the client looks like DLB loop DLB send data to server DLB read reply (blocking) DLB do nasty computation DLB end loop DLB then it not only has to compete for CPU time, it does nothing while DLB waiting for the server to
Re: Dabo in 30 seconds?
Ed Leafe [EMAIL PROTECTED] writes: I am going to go ahead and throw out Dabo with all of the others that claim quick development of an application. You try them and then you get bugs, bugs, bugs. Or they don't compile without 16000 dependencies. Forget it. My advice is to choose something, one thing, that is REAL standard, and in the standard library (e.g. Tkinter). Sorry you feel that way. You'll miss out on really great Python products that aren't in the standard Library, such as Twisted, Zope/Plone, Dabo, and many others. ... Python is a base. You build from there. Those issues about the 1600 dependencies don't apply nearly as much to pure Python modules (e.g. Twisted) as they do to extension modules that require the presence of further stuff on the system. E.g., on Linux, to use wxPython, you need wxWidgets, which needs GTK 1.5, which has been obsolete for years, and there are all sorts of build conflicts when you try to compile this stuff out of the box. I don't know where Dabo fits in. It does sound nice in some regards. Pico Lisp uses an interesting approach to portable GUI's: it includes a socket-based GUI API and a special Java applet that runs in a browser and implements the API. All the issues of dealing with OS-specific window systems go away, as long as you can run a Java-enabled browser and point it at the Pico Lisp application. See: http://www.software-lab.de/down.html -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a string like '777' to an octal integer like 0777?
KB wrote: Thanks, John. But my point is how to keep the leading zero in 0777, in order to be used in os.chmod('myfile', 0777)? I don't understand. The leading zero only exists in a particular string representation. os.chmod() needs an integer, not a string. 0777 == 511. os.chmod('myfile', 0777) os.chmod('myfile', 511) os.chmod('myfile', int('777', 8)) They all do *exactly* the same thing. End of story. If you really need a string representation in octal (os.chmod() doesn't), then use oct() on the integer. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: [path-PEP] Path inherits from basestring again
phil hunt wrote: On Sat, 30 Jul 2005 19:01:49 +0200, Reinhold Birkenfeld [EMAIL PROTECTED] wrote: phil hunt wrote: def normalizePath(p, *pathParts): Normalize a file path, by expanding the user name and getting the absolute path.. @param p [string] = a path to a file or directory @param pathParts [list of string] = optional path parts @return [string] = the same path, normalized p1 = os.path.abspath(os.path.expanduser(p)) if len(pathParts)0: allPathParts = [ p1 ] allPathParts.extend(pathParts) p1 = os.path.join(*allPathParts) p2 = os.path.abspath(p1) return p2 normalisePath=normalizePath # alternate spelling join=normalizePath # it works like os.path.join, but better To be honest I don't see the point of having a Path class. That's the way Java does it, and I find path handling in Java to be a lot more of a hassle than in Python. (Actually, most things are more of a hassle in Java, but that's another story). You see, with the Path class the above function could be written as def normalizePath(p, *pathParts): Normalize a file path, by expanding the user name and getting the absolute path.. @param p [Path] = a path to a file or directory @param pathParts [list of string/Path] = optional path parts @return [Path] = the same path, normalized tp = p.expanduser().abspath() return tp.joinwith(*pathParts).abspath() That's clearly an improvement, isn't it? An improvement to what? To how the class is implemented, or to how it is used? No, the second function is cleaner and more readable than the first, IMHO. If you mean the former, yes is it, due to the os.path module not providing a function that does this. If you mean the latter, I disagree, because I would then have to call it with something like: pn = normalizePath(Path(p), q) That's easily helped by s/tp = p/tp = Path(p)/. and then I would have the problem that (pn) isn't a string so calling a function to write some data into the file at that filename would no longer work, i.e. this: writeFile(pn, someData) would become this: writeFile(pn.getString(), someData) Why? A Path is a string. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Thaughts from an (almost) Lurker.
Paddy wrote: Sometimes when reading c.l.p. I mentally stand off from what I have been reading and get an odd feeling that 'WE ARE BEING TESTED'. That someone else is purposefully posting a near repetitive post, or obvious flame bait etc - not for the usual reasons, but to track the dynamics af the replies. Rather like dropping a stone in the river and watching pythonistas return c.l.p. to its normal, helpful, and polite norm. Fascinating. I only hope that if thats the case, then they should post their findings here. My experience with USENET suggests that there is always a steady stream of newbies, trolls, and otherwise clueless people. In the absence of real evidence (like traceable headers), I don't think there's a reason to suspect that there's someone performing psychological experiments on the denizens of c.l.py. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Dabo in 30 seconds?
Paul Rubin wrote: E.g., on Linux, to use wxPython, you need wxWidgets, which needs GTK 1.5, which has been obsolete for years, Nope. It's on GTK2 now. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Hallöchen! Cliff Wells [EMAIL PROTECTED] writes: [...] The least headache for end users comes from properly packaging your application. End users shouldn't need to worry about installing third party packages (or even Python for that matter). Tools such as py2exe and Inno installer make this pretty simple on Windows, and py2app on OS/X accomplishes the same. Does py2exe work for all GUI libraries? It'll highly probably work with Tkinter, and I've read that it also works with pyGTK, but does it also work with wxPython or PyQt? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: Dabo in 30 seconds?
Cliff Wells [EMAIL PROTECTED] writes: Then why are you using Python at all? Shouldn't you be in the safe home of Java or Visual Basic, where standards are all you have? I don't know about VB but Java does a much better job of supporting standards than Python does. Python's advantage is in being a much more pleasant language to code in. It would benefit greatly from also doing a better job implementing standards. Many or most of the Python library modules that purport to implement standards just sort of get halfway there and then stop. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dabo in 30 seconds?
Robert Kern [EMAIL PROTECTED] writes: Linux, to use wxPython, you need wxWidgets, which needs GTK 1.5, which has been obsolete for years, Nope. It's on GTK2 now. Oh, that's recent then. I might try it again in this case. It's still an enormous piece of code. I can't understand why it should need to be so bloated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Torsten Bronger [EMAIL PROTECTED] writes: Does py2exe work for all GUI libraries? No, it's Windows-only. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Cliff Wells [EMAIL PROTECTED] writes: application. End users shouldn't need to worry about installing third party packages (or even Python for that matter). Tools such as py2exe and Inno installer make this pretty simple on Windows, and py2app on OS/X accomplishes the same. It should be irrelevant to end users what libraries or tools you use to develop the app. What if I want to be able to write multi-platform applications without having to deal with OS-specific packaging schemes for every OS that I want to run on? Even if I only want to run on Linux, I don't see how to package a wxPython application to minimize end user hassle. The only realistic GUI's to use are Tkinter or HTTP/HTML over a local socket talking to a user-provided web browser. -- http://mail.python.org/mailman/listinfo/python-list
namespaces
While it's not so bad we can bind names in the module namespace, (ex writing scripts ?) ,writing modules is someway bound to not polluting that namespace (really IMO). For non-functions we can use 'class' : class ns: foo='something' but writing a function there triggers the binding to 'self' behaviour. The straight solution is @staticmethod class ns: @staticmethod def gulp(*args): pass Another solution is via metaclass class namespaceMeta(type): def __init__(cls,*more): ## wrap all methods with staticmethod() class namespace: __metaclass__=namespaceMeta class ns(namespace): def gulp(*args):pass This solution makes me think the keyword 'namespace' is missing: namespace ns: foo='something' def gulp(*args): pass Solutions and comments appreciated. Regards Paolino ___ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Changing interpreter's deafult output/error streams
Hi, Using an embedded interpreter, how do I change it's default output streams (specifically the one used by PyErr_Print() which I'm guessing is the default error stream)? Cheers, Ira -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Paolino wrote: While it's not so bad we can bind names in the module namespace, (ex writing scripts ?) ,writing modules is someway bound to not polluting that namespace (really IMO). I'm afraid that I can't parse that sentence. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 31 Jul 2005 08:22:23 +0200, Torsten Bronger [EMAIL PROTECTED] wrote: What you say Pythonic, what do you mean? And how do you rate Tkinter, PyGtk, PyQt/PyKDE, wxWindows for Pythonicness? I don't like to set arguments to -1 or NULL, but to None. Fair enough I'd like to have extensive support for keyword arguments. Tkinter has that -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
phil hunt wrote: OK, hows this for an idea: 1. create a new API, loosely based on the Tkinter API, but more Pythonic 2. implement Tk using this API (probably won't be difficult because we can use Tkinter as a base) 3. Implement bindings to Gtk and Qt/KDE using this API. Like PyGUI, more or less? http://www.cosc.canterbury.ac.nz/~greg/python_gui/ -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Hallöchen! Paul Rubin http://[EMAIL PROTECTED] writes: Torsten Bronger [EMAIL PROTECTED] writes: Does py2exe work for all GUI libraries? No, it's Windows-only. However, OS'es and GUI libraries are different axes in the space of possibilities. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Robert Kern wrote: Paolino wrote: While it's not so bad we can bind names in the module namespace, (ex writing scripts ?) ,writing modules is someway bound to not polluting that namespace (really IMO). I'm afraid that I can't parse that sentence. I show you a piece of code I need to define a function: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def translate(text): return text.translate(table) What I'm needing as a global (in globals() or at the module level or in the module namespace) is 'translate'.The rest of bindings (all,badcars and table) is something which is 'polluting' the module namespace. Now this is the non polluting version : class translate: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) @staticmethod def __call__(text,table=string.maketrans(badcars,'_'*len(badcars))): return text.translate(table) translate=translate() I'd like to have some help from the language in binding names this way. Hope I've been clearer :) Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Paolino wrote: (...) What I'm needing as a global (in globals() or at the module level or in the module namespace) is 'translate'.The rest of bindings (all,badcars and table) is something which is 'polluting' the module namespace. try this: ## yourmodule.py ## def _setup_table(): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) return string.maketrans(badcars,'_'*len(badcars)) TABLE = _setup_table() # optional, get rid of _setup_table symbol del _setup_table() def translate(text): return text.translate(TABLE) HTH, deelan. -- deelan, #1 fan of adriana lima! http://www.deelan.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
deelan wrote: (...) # optional, get rid of _setup_table symbol del _setup_table() damn copy and paste :) of course i meant: del _setup_table -- deelan, #1 fan of adriana lima! http://www.deelan.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
Jan Danielsson wrote: In [3]: s.encode('string_escape') Out[3]: 'Hello\\nWorld!' In [4]: Out[3].decode('string_escape') Out[4]: 'Hello\nWorld!' Not *quite* what you asked for, but it ought to be close enough. That'll do just fine. Many thanks! Hmm... On second thought, I need to escape more characters. Is there no other way to escape characters in strings? -- http://mail.python.org/mailman/listinfo/python-list
Re: Escaping certain characters
Jan Danielsson wrote: Jan Danielsson wrote: In [3]: s.encode('string_escape') Out[3]: 'Hello\\nWorld!' In [4]: Out[3].decode('string_escape') Out[4]: 'Hello\nWorld!' Not *quite* what you asked for, but it ought to be close enough. That'll do just fine. Many thanks! Hmm... On second thought, I need to escape more characters. Is there no other way to escape characters in strings? Which characters? -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a string like '777' to an octal integer like 0777?
On Sun, 31 Jul 2005 00:24:08 -0700, KB wrote: Thanks, John. But my point is how to keep the leading zero in 0777, in order to be used in os.chmod('myfile', 0777)? os.chmod('myfile', 0777) Python will recognise integers written in octal if you leave a leading zero, and in hex if you use a leading 0x or 0X. 010 8 0x10 16 010 + 0x10 24 As John pointed out, you don't have to use octal for chmod. You can use decimal, or hex -- anything that is an integer. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
On Sun, 31 Jul 2005 12:44:46 +0200, Paolino wrote: I show you a piece of code I need to define a function: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def translate(text): return text.translate(table) Or do this: def translate(text): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) return text.translate(table) No pollution. What I'm needing as a global (in globals() or at the module level or in the module namespace) is 'translate'.The rest of bindings (all,badcars and table) is something which is 'polluting' the module namespace. Then after you are finished with the bindings, delete them: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def translate(text): return text.translate(table) # clean up the temporary variables so as to prevent namespace pollution del string; del all; del badcars; del table -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Google maps on your mobile phone with python for series60
I have written some simple prototype to display google maps data on mobile phone (Nokia Series 60). http://discussion.forum.nokia.com/forum/showthread.php?threadid=63694 Now it can scroll, zoom in, zoom out and toggle between map and sattelite mode. The current code is 100 lines (exactly). You may have some good ideas and try adding it to the code. (smooth scrolling and zooming come to mind) You need to install the python for series 60 1.1.6 first http://www.forum.nokia.com/main/0,,034-821,00.html Korakot Chaovavanich -- http://mail.python.org/mailman/listinfo/python-list
Re: python SMTP server
Fernando M. wrote: Hi, i made a test with smtplib module a few days ago, for sending mails, and i was wondering if there's another module for running an SMTP server, so i could make a standalone script for sending mails without using an external SMTP server. I've been searching but i'm not sure if there are modules for it, or anything. Which ones are my options? An SMTP server is (simplified) a program that listens on port 25 for incoming mails. What you probably want to do is: Do a DNS query for the recipent's domain and use smtplib to connect to the server specified in the MX record. There was a module for DNS querie (not in Python's stdlib), but I forgot how it was called or where you could find it (try the Vaults of Parnassus or PyPI). Or you may use an external tool like 'dig' ('dig mx DOMAIN'). But you should be aware of the fact that (if you send mail from a dialup machine without going through a relay server) your mails will quickly be marked as spam - I hope you do not intend to send spam... -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://www.odahoda.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
deelan wrote in news:[EMAIL PROTECTED] in comp.lang.python: Paolino wrote: (...) What I'm needing as a global (in globals() or at the module level or in the module namespace) is 'translate'.The rest of bindings (all,badcars and table) is something which is 'polluting' the module namespace. try this: ## yourmodule.py ## def _setup_table(): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) return string.maketrans(badcars,'_'*len(badcars)) TABLE = _setup_table() # optional, get rid of _setup_table symbol del _setup_table() def translate(text): return text.translate(TABLE) After 3 or 4 iterations I refactored you code to this: def translate( text ) import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) TABLE = string.maketrans(badcars,'_'*len(badcars)) global translate def translate( text ): return text.translate(TABLE) print First Call! , # -- Just for demonstration -- return translate( text ) print translate(If I was ...) print translate(If I was ...) Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Paolino [EMAIL PROTECTED] writes: What I'm needing as a global (in globals() or at the module level or in the module namespace) is 'translate'.The rest of bindings (all,badcars and table) is something which is 'polluting' the module namespace. do you want __all__ = ['translate'] ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Torsten Bronger [EMAIL PROTECTED] writes: Does py2exe work for all GUI libraries? No, it's Windows-only. However, OS'es and GUI libraries are different axes in the space of possibilities. I'm not sure what you mean. Whatever GUI library the Mac uses, py2exe doesn't work with it, since py2exe doesn't work for Macs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Hallöchen! Paul Rubin http://[EMAIL PROTECTED] writes: Torsten Bronger [EMAIL PROTECTED] writes: Does py2exe work for all GUI libraries? No, it's Windows-only. However, OS'es and GUI libraries are different axes in the space of possibilities. I'm not sure what you mean. I didn't ask does it work with OSX but does it work with wxPython or PyQt. py2exe only creates Windows files, that's right, but why is this important here? Be that as it may, some Google postings suggest that it works at least with wxPython. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing a log handle to a module? Help needed with logging module and
rh0dium wrote: But I can't figure out how to pass the [EMAIL PROTECTED] logging handle to the called module - I'm sorry, but what have you tried? It seems like it should be a simple matter of calling module.main(log). much less change the getLogger name to module. Why do you want to do this? -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Torsten Bronger [EMAIL PROTECTED] writes: Does py2exe work for all GUI libraries? No, it's Windows-only. I didn't ask does it work with OSX but does it work with wxPython or PyQt. py2exe only creates Windows files, that's right, but why is this important here? You asked whether it works with all GUI libraries. If the context limited all to wxPython or PyQt, I missed that. At any rate, I believe it does work with wxPython under Windows. I don't know about PyQt. It doesn't work with any non-Windows libraries. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sunday 31 July 2005 01:02, phil hunt wrote: You mightn't have, but I suspect more Python programers who've written GUI apps have used Tkinter than any of the other APIs. Not that I'm a particular fan of it, it's just I like standardisation, because then you get network effects. At PyCon DC 2004, Guido was asked about wxPython: wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. I don't think that this is a sign that we should discourage further work with wxPython. -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Mike Meyer wrote: [ Having GUI stuff included on a standard installation of Python ] However, you can get compilers for both that come bundled with a good GUI library. Could it be that that's what you really want - someone to distribute Python bundled with an enterprise-class GUI library and IDE? And then you are going to have three or four different distributors of Python using three or four different GUI toolkits and also python.org distributing Python for free without any (or with TKinter)... Which one will be the standard distributor so that it gets documented and adopted? In an international project I see othe problems as well -- cost, logistics, SH, customs, etc. -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Steven D'Aprano wrote: def translate(text): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) return text.translate(table) No pollution. And no efficience.Recalculating all,badcars and table was not an acceptable solution ,sorry if I didn't state this point :( Then after you are finished with the bindings, delete them: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def translate(text): return text.translate(table) # clean up the temporary variables so as to prevent namespace pollution del string; del all; del badcars; del table Well,a solution but not a programming pattern for an elegant language ? More this is also loosing informations. Probably I've not been clear with the word pollution and the example is poor. I didn't mean 'binding to unuseful informations' but 'bindings in a non -structured organization' I restate the problem.Python is in some ways unable to project the module structure inside the module.Or ... namespace pattern instances seems not deriving from a common pattern. Finally, (before I get polemic which is not my aim) I start thinking classes (namespaces defined via 'class' keyword) are a specialization of generic namespaces in which there-defined methods get a special way of being called and __call__ method is a way of cloning access to them. (Thin ice) Don't really know if modules can be defined as specialization of generic namespaces and be placed somewhere next to classes. Even worse I get with methods and function namespaces. Rob Williscroft wrote: After 3 or 4 iterations I refactored you code to this: def translate( text ) import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) TABLE = string.maketrans(badcars,'_'*len(badcars)) global translate def translate( text ): return text.translate(TABLE) return translate( text ) There is a way to access 'all' and 'badcars' here? In my trial translate.all and translate.badcars can be accessed easily and maybe coherently. Thanks a lot, and don't tell me 'the dictator has marked the trail' ;) ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list
Newb: Telnet 'cooked data','EOF' queries.
While experimenting with telnetlib, Ive come across a couple of 'features' that confuse me a little (lot!). Could someone explain what cooked data is. Also when trying read_all() the program seems to lock up, which I assume is because it is waiting for an EOF, but 'when' is an EOF received. Glen -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Paolino wrote in news:mailman.2453.1122812091.10512.python- [EMAIL PROTECTED] in comp.lang.python: Rob Williscroft wrote: After 3 or 4 iterations I refactored you code to this: def translate( text ) import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) TABLE = string.maketrans(badcars,'_'*len(badcars)) global translate def translate( text ): return text.translate(TABLE) return translate( text ) There is a way to access 'all' and 'badcars' here? In my trial translate.all and translate.badcars can be accessed easily and maybe coherently. I had to do this inorder to access them: def translate( text ): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) TABLE = string.maketrans(badcars,'_'*len(badcars)) global translate def translate( text ): return text.translate(TABLE) print First Call! , # -- Just to showoff -- translate.all = all translate.badcars = badcars return translate( text ) print translate(If I was ...) print translate(If I was ...) print badcars:, len(translate.badcars) CPython 2.4 on windows XP. But maybe you mean something else ? Thanks a lot, and don't tell me 'the dictator has marked the trail' ;) I got the idea from Hung Jung Lu, here: http://groups.google.co.uk/group/comp.lang.python/msg/1e63e07c7d83cc7d How the trail got there I've no idea ;-) Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: keylogger in Python
Jay wrote: yo, thanks for the great input. And the only reason i want to create a python based keylogger is because there is none. Just a fun project... But im gonna do some more research on the keyboard drivers and stuff like that and to learn how to attach my python porgrams into the sub-processes so that it would instead log every char instead of just char in the IDE. I think this is going to be much harder than you think, and I imagine this will only end in frustration for you. You will not be able to do it well with just Python. I would recommend a different fun project. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Newb: Telnet 'cooked data','EOF' queries.
On Sun, Jul 31, 2005 at 01:30:43PM +0100, glen wrote: Could someone explain what cooked data is. The telnet protocol contains special sequences which are interpreted by the telnet client or server program. These are discussed in the telnet RFC, which is RFC854 according to the telnetlib docstring. Cooked data is data after these special sequences are removed. Also when trying read_all() the program seems to lock up, which I assume is because it is waiting for an EOF, but 'when' is an EOF received. As far as I know, the only EOF in telnet is when the other side closes the socket. Jeff pgpnCbDvhyN27.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: keylogger in Python
Michael Hoffman wrote: I think this is going to be much harder than you think, and I imagine this will only end in frustration for you. You will not be able to do it well with just Python. I would recommend a different fun project. Actually, it's pretty easy, using the pyHook and Python win32 modules. I use code like this to detect when the user is away from the keyboard. import pyHook import time import pythoncom def OnKeyboardEvent(event): print event.Ascii hm = pyHook.HookManager() hm.KeyDown = OnKeyboardEvent hm.HookKeyboard() while True: pythoncom.PumpMessages() Sw. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Saturday 30 July 2005 01:54 am, Torsten Bronger wrote: Calvin Spealman [EMAIL PROTECTED] writes: The choice is GUI toolkits is largely seperate from Python. Consider that they are just bindings to libraries that are developed completely seperate of the language. GUI is should be seperate from the language, and thus not bound to same expectations and desires as elements of the language itself. I disagree. A modern language must provide a convenient and well-embedded way to write GUI applications. I know I'm diving into this conversation late, and I haven't read the whole thread, but has someone yet mentioned the anygui project? This has stalled, but it was IMHO a good idea. It sounds as if you are re-voicing the need that instigated the project in the first place. http://anygui.sourceforge.net/ AFAIK, the project stalled because not enough people were sufficiently interested in the need. Some people said that just using wx or Tkinter was easier. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: keylogger in Python
[EMAIL PROTECTED] wrote: Actually, it's pretty easy, using the pyHook and Python win32 modules. Well, I'll be. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
On Sun, 31 Jul 2005 15:09:48 +0200, Paolino wrote: Steven D'Aprano wrote: def translate(text): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) return text.translate(table) No pollution. And no efficience.Recalculating all,badcars and table was not an acceptable solution ,sorry if I didn't state this point :( Why not? Is it too slow? Too many lines of code? Uses too much memory? What exactly is the problem? I would like to see your profile tests that show why this is not acceptable. Are you sure that this solution is less efficient than creating a class? A class has all that extra machinery and methods and attributes that needs to be created, only to be thrown away. How do you know that my solution is less efficient than your solution? Then after you are finished with the bindings, delete them: import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) def translate(text): return text.translate(table) # clean up the temporary variables so as to prevent namespace pollution del string; del all; del badcars; del table Well,a solution but not a programming pattern for an elegant language ? More this is also loosing informations. Deleting things you don't need or want is not losing information. You asked for a solution to make the bindings go away. Deleting them makes them go away. Probably I've not been clear with the word pollution and the example is poor. I didn't mean 'binding to unuseful informations' but 'bindings in a non -structured organization' I restate the problem.Python is in some ways unable to project the module structure inside the module.Or ... namespace pattern instances seems not deriving from a common pattern. I'm sorry, but I do not understand this. Finally, (before I get polemic which is not my aim) I start thinking classes (namespaces defined via 'class' keyword) are a specialization of generic namespaces in which there-defined methods get a special way of being called and __call__ method is a way of cloning access to them. (Thin ice) Yes, classes are a namespace. I don't know what you mean by cloning access, but __call__ is the method called for arbitrary objects when you call them as if they were a function: someobject(). Don't really know if modules can be defined as specialization of generic namespaces and be placed somewhere next to classes. Even worse I get with methods and function namespaces. What is even worse about them? Quoting Rob Williscroft: def translate( text ) import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) TABLE = string.maketrans(badcars,'_'*len(badcars)) global translate def translate( text ): return text.translate(TABLE) return translate( text ) This is a difficult piece of code to understand and maintain. You have a function called translate, which in turn calls the string translate() method. That's okay. But then you have a global variable *also* called translate -- does that refer to the same function? Is this self-modifying code? That is a dangerous, hard to debug, hard to understand technique that is too-clever-by-half. Then you create a local variable, also called translate, also a function, which simply calls the translate method of its argument. A waste of a function, when all you need to do is call the pre-existing translate method. If I have understood this code correctly, the *local* translate is bound to the *global* translate, which is the function being defined. And lastly, just to complete the confusion, the original function itself appears to call itself -- presumably the rebound copy that points to what was the local copy -- recursively, with the same argument. That's a nifty piece of code for showing how clever you are at writing mildly obfuscated code. But for commercial use, where the code has to be maintained and debugged, it is a terrible idea. There is a way to access 'all' and 'badcars' here? I can't see any way to access them. Isn't that the point? You don't want them available? In my trial translate.all and translate.badcars can be accessed easily and maybe coherently. Yes, and you asked for that not to happen. That's what namespace pollution means -- you get temporary objects persisting after you no longer need them, and showing up in the namespace when you don't want them there. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Hallöchen! Terry Hancock [EMAIL PROTECTED] writes: On Saturday 30 July 2005 01:54 am, Torsten Bronger wrote: Calvin Spealman [EMAIL PROTECTED] writes: The choice is GUI toolkits is largely seperate from Python. Consider that they are just bindings to libraries that are developed completely seperate of the language. GUI is should be seperate from the language, and thus not bound to same expectations and desires as elements of the language itself. I disagree. A modern language must provide a convenient and well-embedded way to write GUI applications. I know I'm diving into this conversation late, and I haven't read the whole thread, but has someone yet mentioned the anygui project? This has stalled, but it was IMHO a good idea. I don't know exactly why this project died, but I'd start with a Pythonic variant of wxPython. I've read many discussions about the people who didn't like the wxPython's C++ style, so there are chances to get fellow developers and users. You must reach the critical mass quickly in order to get a survivable project, and being not too far away from an existing one is a good stating point. Possibly Dabo manages such a thing. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: keylogger in Python
[Michael Hoffman] Jay wrote: yo, thanks for the great input. And the only reason i want to create a python based keylogger is because there is none. Just a fun project... But im gonna do some more research on the keyboard drivers and stuff like that and to learn how to attach my python porgrams into the sub-processes so that it would instead log every char instead of just char in the IDE. I think this is going to be much harder than you think, and I imagine this will only end in frustration for you. You will not be able to do it well with just Python. I would recommend a different fun project. I'm just stumbling on that message, and did not follow the whole thread, sorry if I repeat things already discussed. My point is that Python is able to do surprising things, given the `fcntl' and `ioctl' modules. Surely on Linux, logging keys under X-Windows or under virtual terminals are quite different matters. Let me share a related experience for virtual terminals. I once had to rush the port on Linux a few QNX applications, written in C, which were using the QNX term library for input and display. In console mode, the QNX keyboard is richer than the Linux one. As users wanted to retain the _exact_ keyboard functionality, I saw no choice but reading raw scan codes on the Linux side. So, I wrote a term library emulator as a thin C layer, which was itself using a Python module (Python was to be transparently embedded by the emulated library) for doing the bulk of keyboard processing. It was something pretty heretic to do, I know. But Python was more than fast enough for handling the low-level keyboard reading, for applications otherwise all written in C. But it allowed the port to be done quickly. While debugging such a thing, you often loose the keyboard and with it, the capability of switching terminals, so you have to devise some extra machinery for restoring the keyboard into a usable state. -- François Pinard http://pinard.progiciels-bpi.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sunday 31 July 2005 10:32, Torsten Bronger wrote: I know I'm diving into this conversation late, and I haven't read the whole thread, but has someone yet mentioned the anygui project? This has stalled, but it was IMHO a good idea. I don't know exactly why this project died, but I'd start with a Pythonic variant of wxPython. I've read many discussions about the people who didn't like the wxPython's C++ style, so there are chances to get fellow developers and users. You must reach the critical mass quickly in order to get a survivable project, and being not too far away from an existing one is a good stating point. Possibly Dabo manages such a thing. We certainly are striving for such a goal. And while Dabo only supports wxPython now, we've designed the UI layer so that it is toolkit-agnostic (in theory, at least). After we have a full, robust implementation using wxPython, we then plan on implementing Tkinter and Qt, assuming that there is demand for those toolkits. But since UIs are incredibly complex beasts, we've chosen to tackle one at a time, and after looking at them all and considering different issues, we chose wxPython as the best toolkit for creating platform-independent apps. -- -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Trimming X/HTML files
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 The regular expression remove script out of an HTML/XHTML file is simple enough but raises a major performance issue The following regular expression : r'(script(\s*\S+\s*)+/script)' takes ages to complete in python on simple HTML file more than 3 minutes of CPU time on a 150 lines HTML file. In jython it just never completes but returns a painfull RunTimeException : maximum number of ??? reached. Is the only way out dealing with strings and match instead of regular expression ? More over Jython is not yet 2.3 compliant, hence advanced features of 2.3 regular expression are not yet available ! \T, Thomas SMETS wrote: | | Dear, | | I need to parse XHTML/HTML files in all ways : | ~ _ Removing comments and javascripts is a first issue | ~ _ Retrieving the list of fields to submit is my following item (todo) | | Any idea where I could find this already made ... ? | | \T, | | - -- Thomas SMETS Bruxelles @ : [EMAIL PROTECTED] -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD4DBQFC7OkTqN0SJr+xLBURAuTYAKDLxLv+hpnSrZ6uowOmUczVxgxLqwCYhfJ3 fwjPZzg88gh3lNY8jkG3SA== =urIC -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: keylogger in Python
François Pinard wrote: Surely on Linux, logging keys under X-Windows or under virtual terminals are quite different matters. Let me share a related experience for virtual terminals. I once had to rush the port on Linux a few QNX applications, written in C, which were using the QNX term library for input and display. In console mode, the QNX keyboard is richer than the Linux one. As users wanted to retain the _exact_ keyboard functionality, I saw no choice but reading raw scan codes on the Linux side. So, I wrote a term library emulator as a thin C layer, which was itself using a Python module (Python was to be transparently embedded by the emulated library) for doing the bulk of keyboard processing. You think this is a suitable beginner project? And for that matter, it doesn't sound like you were doing keylogging, as it is usually understood to mean globally logging keypresses, no matter the application being presented to the user. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
getting an empty tuple
Hey there, i have a simple database query that returns as a tuple the number of rows that the query selected. kinda like this cursor.execute('select value from table where autoinc 234') x = cursor.fetchall() print x 21L ok, means 21 rows met the criteria of the query. but if there are none that match, like i do a print x 0L how do i encorporate that into an equation ? i have tried all kinds of stuff if x == 0L if x(0) == None if x == None anyway, what shoud i do to test if the result is empty? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: getting an empty tuple
On 31 Jul 2005 08:40:26 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: how do i encorporate that into an equation ? i have tried all kinds of stuff if x == 0L if x(0) == None if x == None anyway, what shoud i do to test if the result is empty? Just like any other test: if not x: -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Thaughts from an (almost) Lurker.
Robert Kern wrote: My experience with USENET suggests that there is always a steady stream of newbies, trolls, and otherwise clueless people. In the absence of real evidence (like traceable headers), I don't think there's a reason to suspect that there's someone performing psychological experiments on the denizens of c.l.py. Er... yes! Exactly! These are not the trolls you're looking for, move along. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: keylogger in Python
[Michael Hoffman] You think this is a suitable beginner project? One surely learns a lot! :-) And for that matter, it doesn't sound like you were doing keylogging, as it is usually understood to mean globally logging keypresses, no matter the application being presented to the user. One possible avenue to keylogging might be to start a shell, over the keyboard processing layer, presuming the shell do only simple things over its standard input. But most likely, the shell is playing termios trickery and such things. So one might have to use pty's to get a working solution. Agreed, this is not all evident, and probably too much of a challenge for a beginner. -- François Pinard http://pinard.progiciels-bpi.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Ed Leafe [EMAIL PROTECTED] writes: But since UIs are incredibly complex beasts, we've chosen to tackle one at a time, and after looking at them all and considering different issues, we chose wxPython as the best toolkit for creating platform-independent apps. How on earth did you decide that, since tkinter actually runs out of the box when you install Python on most platforms, and wxPython doesn't? I can't even think about trying out Dabo unless I'm willing to go through some enormous pain of getting wxPython to work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Hallöchen! Paul Rubin http://[EMAIL PROTECTED] writes: Ed Leafe [EMAIL PROTECTED] writes: But since UIs are incredibly complex beasts, we've chosen to tackle one at a time, and after looking at them all and considering different issues, we chose wxPython as the best toolkit for creating platform-independent apps. How on earth did you decide that, since tkinter actually runs out of the box when you install Python on most platforms, and wxPython doesn't? I can't really understand your hostility towards non-Tkinter toolkits. In the case of wxPython, it's part of SUSE, which is probably also true for Fedora and Mandriva. Installing is as easy as selecting a checkbox. This covers a very great deal of Linux users. On Windows you have to call an exe file. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Paolino wrote: Steven D'Aprano wrote: def translate(text): import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) table=string.maketrans(badcars,'_'*len(badcars)) return text.translate(table) No pollution. And no efficience.Recalculating all,badcars and table was not an acceptable solution ,sorry if I didn't state this point :( Then write a closure. You get both encapsulation and efficience, and as a bonus, customization of the translating function: import string def translateFactory(validChars=string.letters+string.digits, replaceChar='_'): all=string.maketrans('','') badcars=all.translate(all,validChars) table=string.maketrans(badcars, replaceChar*len(badcars)) def translate(text): return text.translate(table) # bind any attributes you want to be accessible # translate.badcars = badcars # ... return translate tr = translateFactory() tr(Hel\xfflo) George -- http://mail.python.org/mailman/listinfo/python-list
Re: Thaughts from an (almost) Lurker.
Paddy wrote: Sometimes when reading c.l.p. I mentally stand off from what I have been reading and get an odd feeling that 'WE ARE BEING TESTED'. That someone else is purposefully posting a near repetitive post, or obvious flame bait etc - not for the usual reasons, but to track the dynamics af the replies. Rather like dropping a stone in the river and watching pythonistas return c.l.p. to its normal, helpful, and polite norm. Fascinating. I only hope that if thats the case, then they should post their findings here. Hmm... was that a test, too? ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 31 Jul 2005 02:23:39 -0700, Robert Kern [EMAIL PROTECTED] wrote: Like PyGUI, more or less? http://www.cosc.canterbury.ac.nz/~greg/python_gui/ We ended up using (py)Qt, and it's a nice library but to my eyes is a lot un-pythonic. In many cases there are convoluted solutions that seem to me good ideas for a C++ library, but that just do not make any sense in Python where the problem they solve simply do not exist. My impression about PyGUI is that it would be (would have been?) a nice plug for a hole in the python offer, unfortunately I also perceive the clear impression the authors don't (didn't?) actually want it to be used in the real world. Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: getting an empty tuple
On Sun, 31 Jul 2005 08:40:26 -0700, nephish wrote: Hey there, i have a simple database query that returns as a tuple the number of rows that the query selected. kinda like this cursor.execute('select value from table where autoinc 234') x = cursor.fetchall() print x 21L 21L is not a tuple, it is a long integer. ok, means 21 rows met the criteria of the query. but if there are none that match, like i do a print x 0L how do i encorporate that into an equation ? i have tried all kinds of stuff And did they work? If they didn't work, tell us the exact error message you got. if x == 0L If x is a long integer, then that will work. Of just if x == 0: will work too. if x(0) == None No. That means x is a function, and you are giving it an argument of 0, and it returns None. if x == None You said that your query returns a tuple, but then gave an example where it returns a long int. None is not a tuple, nor a long int, so testing either of those things against None will never be true. Did you try any of these things in the interactive interpreter? Python is a great language for experimenting, because you can try this yourself: # run your setup code ... # and then do some experimenting cursor.execute('select value from table where autoinc ') # or some value that will never happen x = cursor.fetchall() print x What do you get? anyway, what shoud i do to test if the result is empty? Long ints are never empty, but they can be zero: if x == 0: print no rows were found elif x == 1: print 1 row was found else: print %d rows were found % x Tuples can be empty: if len(x) == 0: print no rows were found or if you prefer: if x == (): print no rows were found But the cleanest, most Pythonic way is just to do a truth-test: if x: print something was found else: print x is empty, false, blank, nothing... -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Steven D'Aprano wrote in news:[EMAIL PROTECTED] in comp.lang.python: Quoting Rob Williscroft: def translate( text ) import string all=string.maketrans('','') badcars=all.translate(all,string.letters+string.digits) TABLE = string.maketrans(badcars,'_'*len(badcars)) global translate def translate( text ): return text.translate(TABLE) return translate( text ) This is a difficult piece of code to understand and maintain. Its 8 lines, of self contained code. It does everyting its supposed to do and nothing its not. You have a function called translate, which in turn calls the string translate() method. That's okay. But then you have a global variable *also* called translate -- does that refer to the same function? This is how globals work in python, if you wish to (re)bind to a global before reading it at function scope, you need to say so. Is this self-modifying code? That is a dangerous, hard to debug, hard to understand technique that is too-clever-by-half. Maybe so, but if true, python as a language is too-clever-by-half. Then you create a local variable, also called translate, also a No, that isn't how globals work in python, there is no local called translate above. function, which simply calls the translate method of its argument. A waste of a function, when all you need to do is call the pre-existing translate method. If I have understood this code correctly, the *local* translate is bound to the *global* translate, which is the function being defined. Close but there isn't, and never was, a *local* translate function. And lastly, just to complete the confusion, the original function itself appears to call itself -- presumably the rebound copy that points to what was the local copy -- recursively, with the same argument. def f() global g def g(): return something return g() f() is a function that (re)creates a global function g() and calls it. Is it just that translate() rebinds itself that is too much, or do you object to f() too ? I do object to f() but only because its useless. That's a nifty piece of code for showing how clever you are at writing mildly obfuscated code. But for commercial use, where the code has to be maintained and debugged, it is a terrible idea. 8 lines of self contained code are a terrible idea !, you have IMO a very strange idea of what is or isn't maintainable. Is using generators and decorators a terrible idea too ? Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Ed Leafe wrote: On Sunday 31 July 2005 01:02, phil hunt wrote: You mightn't have, but I suspect more Python programers who've written GUI apps have used Tkinter than any of the other APIs. Not that I'm a particular fan of it, it's just I like standardisation, because then you get network effects. At PyCon DC 2004, Guido was asked about wxPython: wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. Maybe. But Guidos intention with Python was to create a secondary language originally - an extension language of C - ( unlike Java that was concepted as a radically platform independent language and a successor of C++ ). Now since Python is 15 years old, some people start learning Python as their primary language and they begin to ask why it does not support a native GUI toolkit like TCL with Tk i.e. something in it's own right with just some C-modules for interfacing with OS dependent libs ( if any - thanks to the ctypes ffi ! ) and some other extensions for optimization and maybe scintilla for pluging it in. Some other people already abandoned Python not for the worst reasons: http://www.kevin-walzer.com/pivot/entry.php?id=69 My objection with wrappers around wrappers around wrappers is that I have no hope ever watching the ground. If some error occurs, which layer has to be addressed? Which developing group is reponsible? My own or that of team A, team B, team C ... ? The baroque concept is repulsive to me and only acceptable in case of legacy code that gets wrapped around old one and is dedicated to substitute it continously. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: string methods
anthonyberet wrote: For example if I wanted to replace the 4th character in 'foobar' (the b)with the contents of another string, newchar, what would be the easiest way? Depends on how your input is specified. If you know it is the b you want to replace, you write text=foobar text = text.replace(b,baz) text 'foobazar' There is no issue with immutability here: .replace returns a new string object, and you assign this to the text variable (thus dropping the reference to the string foobar). If you know it is the fourth character you want to replace, you do as people have suggested: text=foobar text=text[:3]+baz+text[4:] text 'foobazar' And, if you know in advance that the string is foobar, and that it is the fourth character, and that the replacement string is baz, you write text=foobazar :-) Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: c/c++ extensions and help()
Robert Kern [EMAIL PROTECTED] writes: Lenny G. wrote: Is there a way to make a c/c++ extension have a useful method signature? Right now, help(myCFunc) shows up like: myCFunc(...) description of myCFunc I'd like to be able to see: myCFunc(myArg1, myArg2) description of myCFunc Is this currently possible? There really isn't a way to let the inspect module know about extension function arguments. Just put it in the docstring. The next release of boost.python should do this automatically: (http://mail.python.org/pipermail/c++-sig/2005-July/009243.html) help(rational.lcm) Help on built-in function lcm: lcm(...) C++ signature: lcm(int, int) - int help(rational.int().numerator) Help on method numerator: numerator(...) method of boost_rational_ext.int instance C++ signature: numerator(boost::rationalint {lvalue}) - int Regards, Phil -- http://mail.python.org/mailman/listinfo/python-list
__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)
Hello python-list, As I Understood, semantic may be next: def qwerty(a,a.i,b,b.i,f.j): pass Would work like: def qwerty(anonymous1,anonymous2,anonymous3,anonymous4,anonymous5): (a,a.i,b,b.i,f.j)=(anonymous1,anonymous2,anonymous3,anonymous4,anonymous5) del anonymous1 del anonymous2 del anonymous3 del anonymous4 del anonymous5 If so then I like it, because it more explicit than anything other and it is working right now. I just tryed: class Stub: ... pass def qwer(a1,a2,a3,a4,a5): ... (a,a.i,b,b.i,f['i'])=(a1,a2,a3,a4,a5) ... del a1 ... del a2 ... del a3 ... del a4 ... del a5 ... print (a,a.i,b,b.i,f['i']) f={} qwer(Stub(),1,Stub(),2,3) (__main__.Stub instance at 0x00C49530, 1, __main__.Stub instance at 0x00C498C8, 2, 3) So there are not too much for implement. Another question - named arguments. How I can assign to them? May be so: f={} def qwerty(a,a.i,f['i']): print (a,a.i,f['i']) qwerty(f['i']=3,a=Stub(),a.i=4) - ? and for __init__: class MyClass: def __init__(self,self.i,self.j,self.k): pass MyObject = MyClass(self.i=1,self.j=2,self.k=3) ? or may be there can be an aliase syntax? class MyClass: def __init__(self, self.i by i,self.j by j, self.k by k): pass MyObject = MyClass(i=1,j=2,k=3) -- Sokolov Yura [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
phil hunt wrote: But, what if the Python documentation was on a Wiki? Then it would be easy to update! Of course, we would have to guard against false or malicious updates, but Wikipedia manage that OK. The Documentation Wiki could then be used as a basis for the official documentation that comes with each new release. Does this idea make some sense? Or are there hidden pitfalls? I thought the `Annotatable Python Docs`_ were a good idea but they seem to have fallen into disuse. .. _Annotatable Python Docs: http://pydoc.amk.ca/frame.html -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Your IP Address
html head titleYour IP address/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 style type=text/css !-- body { background-color: ##BBE1DF; } .style1 { font-size: 36px; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; } -- /style/head body div align=center class=style1a href=http://www.ipimne.com;Your IP address br br www.ipimne.com/a/div /body /html -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
Steven D'Aprano wrote: Why not? Is it too slow? Too many lines of code? Uses too much memory? What exactly is the problem? I would like to see your profile tests that show why this is not acceptable. Are you sure that this solution is less efficient than creating a class? A class has all that extra machinery and methods and attributes that needs to be created, only to be thrown away. How do you know that my solution is less efficient than your solution? The example was an example , and my concern is not about that example to be fast or small (readable probably), but for python programming tools as being complete, or academic interest or just to talk with people on a hot sunday (in this zone of the north emisphere) on interesting (for me at least) things. The calculations for all,badcars and table are not complex in this case, so we can redo them often because we are wasters, but in other cases they can be different. Me: Even worse I get with methods and function namespaces. What is even worse about them? For my thinking, worse is to understand how they derive their pattern from generic namespaces. Methods seems not to have a writeble one,while functions as George and Rob remembered have one which is not read only.Why? (Also my aim is to learn from postings not to show others' implementations are better or worse in the sense I prefer, times are gone for me for that. ) Paolino ___ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 10:01 +0200, Torsten Bronger wrote: Hallöchen! Cliff Wells [EMAIL PROTECTED] writes: [...] The least headache for end users comes from properly packaging your application. End users shouldn't need to worry about installing third party packages (or even Python for that matter). Tools such as py2exe and Inno installer make this pretty simple on Windows, and py2app on OS/X accomplishes the same. Does py2exe work for all GUI libraries? It'll highly probably work with Tkinter, and I've read that it also works with pyGTK, but does it also work with wxPython or PyQt? py2exe and py2app work for wxPython at least, not sure about the other gui toolkits. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 04:23 -0700, Paul Rubin wrote: Torsten Bronger [EMAIL PROTECTED] writes: Does py2exe work for all GUI libraries? No, it's Windows-only. However, OS'es and GUI libraries are different axes in the space of possibilities. I'm not sure what you mean. Whatever GUI library the Mac uses, py2exe doesn't work with it, since py2exe doesn't work for Macs. py2app is the py2exe equivalent for OS/X. And it works fine with wxPython as well. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve: writing out updates?!
Robert Kern [EMAIL PROTECTED] writes: The Documentation Wiki could then be used as a basis for the official documentation that comes with each new release. Does this idea make some sense? Or are there hidden pitfalls? Yes! Someone actually has to do it! I think someone is working on this as part of the summer of code program (but am not sure about that...). Cheers, mwh -- QNX... the OS that walks like a duck, quacks like a duck, but is, in fact, a platypus. ... the adventures of porting duck software to the platypus were avoidable this time.-- Chris Klein, asr -- http://mail.python.org/mailman/listinfo/python-list
Re: Asking the user a question and giving him a default answer he can edit
levander [EMAIL PROTECTED] writes: Basically, I've got a bunch of questions to ask a user, the vast majority of which, the answer will only vary by the last few characters. What I'd like to do is every time the user is asked a question, give him the default answer as just whatever he answered last time. But, I want him to be able to edit this default answer. And, the editted answer is what I want to operate on inside my program. Something like this? / def f(): |.. readline.set_startup_hook(lambda :readline.insert_text('aaa')) |.. return raw_input() \__ Basically, I want to the user a line editor, with a default value already populated. Or you could use my pyrepl package (see google for that). Cheers, mwh -- In case you're not a computer person, I should probably point out that Real Soon Now is a technical term meaning sometime before the heat-death of the universe, maybe. -- Scott Fahlman [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: getting an empty tuple
ok, this is what works: if x == (): sorry about the bad info. and what i ment to put was x[0] not x(0) thanks for the tips its all good now shawn Steven D'Aprano wrote: On Sun, 31 Jul 2005 08:40:26 -0700, nephish wrote: Hey there, i have a simple database query that returns as a tuple the number of rows that the query selected. kinda like this cursor.execute('select value from table where autoinc 234') x = cursor.fetchall() print x 21L 21L is not a tuple, it is a long integer. ok, means 21 rows met the criteria of the query. but if there are none that match, like i do a print x 0L how do i encorporate that into an equation ? i have tried all kinds of stuff And did they work? If they didn't work, tell us the exact error message you got. if x == 0L If x is a long integer, then that will work. Of just if x == 0: will work too. if x(0) == None No. That means x is a function, and you are giving it an argument of 0, and it returns None. if x == None You said that your query returns a tuple, but then gave an example where it returns a long int. None is not a tuple, nor a long int, so testing either of those things against None will never be true. Did you try any of these things in the interactive interpreter? Python is a great language for experimenting, because you can try this yourself: # run your setup code ... # and then do some experimenting cursor.execute('select value from table where autoinc ') # or some value that will never happen x = cursor.fetchall() print x What do you get? anyway, what shoud i do to test if the result is empty? Long ints are never empty, but they can be zero: if x == 0: print no rows were found elif x == 1: print 1 row was found else: print %d rows were found % x Tuples can be empty: if len(x) == 0: print no rows were found or if you prefer: if x == (): print no rows were found But the cleanest, most Pythonic way is just to do a truth-test: if x: print something was found else: print x is empty, false, blank, nothing... -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: namespaces
George Sakkis wrote: Then write a closure. You get both encapsulation and efficience, and as a bonus, customization of the translating function: import string def translateFactory(validChars=string.letters+string.digits, replaceChar='_'): all=string.maketrans('','') badcars=all.translate(all,validChars) table=string.maketrans(badcars, replaceChar*len(badcars)) def translate(text): return text.translate(table) # bind any attributes you want to be accessible # translate.badcars = badcars # ... return translate tr = translateFactory() tr(Hel\xfflo) This is clean,but I suppose it would get cumbersome if I want to have more functions in the namespace/factory and it implies all that bindings in the end. The second point also shows my perplexities about functions namespace: def function(): function.foo='something' a=function.foo Traceback (most recent call last): File stdin, line 1, in ? AttributeError: 'function' object has no attribute 'foo' How should I read it? The namespace is half done inside the function? Thanks Paolino ___ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.beta.messenger.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 01:08 -0700, Paul Rubin wrote: Cliff Wells [EMAIL PROTECTED] writes: application. End users shouldn't need to worry about installing third party packages (or even Python for that matter). Tools such as py2exe and Inno installer make this pretty simple on Windows, and py2app on OS/X accomplishes the same. It should be irrelevant to end users what libraries or tools you use to develop the app. What if I want to be able to write multi-platform applications without having to deal with OS-specific packaging schemes for every OS that I want to run on? Even if I only want to run on Linux, I don't see how to package a wxPython application to minimize end user hassle. The only realistic GUI's to use are Tkinter or HTTP/HTML over a local socket talking to a user-provided web browser. Hm. That's odd, I thought I had just finished a fairly sophisticated app that runs on Windows, Linux and Mac OSX using wxPython... I must be mistaken. Regardless, if you are doing cross-platform work for *end-users* you had better be prepared for a little pain as there is no magic bullet. As far as Linux only apps go... if a Linux user can't figure out how to install wxPython (which is provided in several common packaging formats), then I suspect they are used to pain. The bottom line is this: some people like Tk, some wxPython. Each has advantages and disadvantages. But to claim that you *can only* do something in one or the other only demonstrates that you haven't really tried. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 00:23 -0700, Paul Rubin wrote: [EMAIL PROTECTED] (phil hunt) writes: What you say Pythonic, what do you mean? And how do you rate Tkinter, PyGtk, PyQt/PyKDE, wxWindows for Pythonicness? Tkinter is not very Pythonic because it's sort of a Frankenstein hybrid of Python and Tcl, but at least it's there and it more or less works. The others are non-Pythonic because they're not included in the standard distro and therefore the Pythonic use the included batteries tenet says to use Tkinter despite its flaws. Am I to assume that you don't use *any* third party libraries? As far as the use the included batteries tenet... has Python changed from a programming language to a cult in the few months I've been off the list? Where are these tenets? I've never heard such nonsense. Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing interpreter's deafult output/error streams
Ira [EMAIL PROTECTED] writes: Using an embedded interpreter, how do I change it's default output streams (specifically the one used by PyErr_Print() which I'm guessing is the default error stream)? It looks as though it writes to stderr unconditionally. But most of the reasons for ended up in PyErr_Print can be intercepted at a higher level (I think -- I mean sys.excepthook co here). Cheers, mwh -- ARTHUR: Yes. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard. -- The Hitch-Hikers Guide to the Galaxy, Episode 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Torsten Bronger [EMAIL PROTECTED] writes: Hallöchen! Mike Meyer [EMAIL PROTECTED] writes: Torsten Bronger [EMAIL PROTECTED] writes: Calvin Spealman [EMAIL PROTECTED] writes: The choice is GUI toolkits is largely seperate from Python. Consider that they are just bindings to libraries that are developed completely seperate of the language. GUI is should be seperate from the language, and thus not bound to same expectations and desires as elements of the language itself. I disagree. A modern language must provide a convenient and well-embedded way to write GUI applications. The tools for writing GUI applications belong in a library, not the langauge. None of us has talked about changing syntax. However, the standard library is part of the language unless you're really very petty. Or you use different Python implementations. There are four different Python implementations in the world. Not everything in the CPYthon standard library runs in all of them. Or are you going to claim that someone usin Jython isn't using Python because they can't use the full standard library? If they're using python, then the parts of the standard library they can't use aren't part of the language. Which calls into question everything in the standard library. This is not a sign of decadence, but a very good promotional argument. But it's not required for the language to succeed. Today it is (except for very special-purpose languages). To put this differently, it's required if you want to succeed as a language for the specific purpose of creating GUI applications. I'd agree to that. But there are *lots* of other application areas around, so limiting your definition of success to that one field is very short-sighted. C and C++ are both doing very well without your a well-embedded way to write GUI applications. I don't think that much money is made with new C programs. Almost all money with C++ is made with VC which has been having a GUI toolkit in its standard library right from the beginning. And most money is made with VB AFAIK. Your definition of success is clearly different than mine. You restrict your definition of success to proprietary applications - which I almost never use. If I were using a definition as stilted as yours, I'd say that success was measured by the number of lines of source code in that language that were freely available. By which measure C is still immensely popular, because of the large number of older applications that are written in it that are available - Python being one such. On the other hand, I do recognize that proprietary applications exist. The only real measure of the success of a language is how many applications are being written in it - and that measure will change depending on the application area in question. I'd say Python has succeeded as a web development language, and as a systems scripting language - and I've certainly missed some. Now that it's available for the S60 series phone (I'm going to get one, I swear), I'd say it's set to succeed as a development language for portable devices. None of these are what you call specific-purpose areas, just application development areas that don't need a GUI. By restricting yourself to projects that make money, you're also limiting the apparent success of VB. From what I can tell, most applications written in VB are in-house tools of various kinds. That makes it even more successful than your measure would lead you to believe. C++ succeeded on platforms that VC doesn't run on, so you can hardly claim that VC was responsible for C++'s success. Since you brought up the off-topic point of VB, I'd say that the *most* money is made with SQL. That's based on far to many years of watching the want ads. Almost all of them require some language other than SQL, and a lot of those are indeed VB. However, you can get compilers for both that come bundled with a good GUI library. Could it be that that's what you really want - someone to distribute Python bundled with an enterprise-class GUI library and IDE? Well, a nice thing to have, but besides my point. Then you seem to have missed some of your own points. C++ succeeded without having a standard GUI library. You claimed that that success was because of a single distribution that included the things you are looking for. Why can't the same thing work for Python? We do have a standard library with a robust GUI package, and a standard distribution with a so-called IDE. What I really want is a better GUI included into the standard library. I think you're the first person I've heard call IDLE an IDE. Then again, I don't pay much attention to it. Or maybe you meant something else. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Cliff Wells [EMAIL PROTECTED] writes: On Sun, 2005-07-31 at 00:59 -0400, Mike Meyer wrote: I don't particularly like Tkinter, but it seems to me that it's pretty much won. It seems to be installed on every desktop platform along with Python. That means that if I want to distribute GUI apps, I'm going to cause the least headache for my end users by writing them in Tkinter. By this argument, we should just give up and use Visual* on Windows. Not for me - my end users don't run Windows. Well, some of them may, but for those, my distribution is even easier to use than the ones you build with py2exe. The least headache for end users comes from properly packaging your application. End users shouldn't need to worry about installing third party packages (or even Python for that matter). Tools such as py2exe and Inno installer make this pretty simple on Windows, and py2app on OS/X accomplishes the same. It should be irrelevant to end users what libraries or tools you use to develop the app. And what do I use to bundle my application for Unix? Most of the things I build get installed on Unix servers. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
How override ALL function calls? (Is there a function call function?)
I'm trying run a homegrown profiler on some Python code. Rather than apply profiler wrapper to ALL functions by hand Is there a low level Python function I can override to modify how ALL functions are called? Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 10:07 -0700, Kay Schluehr wrote: Some other people already abandoned Python not for the worst reasons: http://www.kevin-walzer.com/pivot/entry.php?id=69 Being a developer requires not only a bit of brains, but quite a bit of tenacity as well. Apparently Kevin lacks the second. My objection with wrappers around wrappers around wrappers is that I have no hope ever watching the ground. If some error occurs, which layer has to be addressed? Which developing group is reponsible? My own or that of team A, team B, team C ... ? The baroque concept is repulsive to me and only acceptable in case of legacy code that gets wrapped around old one and is dedicated to substitute it continously. Of course, Tkinter is still a wrapper around a third party library (Tk) borrowed from a different language (Tcl) and written again in a third language (C), much the same as wxPython. Your concerns are valid in a theoretical sense, but in practice make little difference. If you are using Tkinter and it exposes a bug in Tk, then you report to the Tkinter maintainers and they will get it fixed. The same can be said for wxPython. Robin Dunn is a wxWidgets developer and if wxPython exposes a bug in wxWidgets, then he will be responsible for getting that bug fixed. As an aside, at one time, Tkinter required that Tcl be installed (and used) in order to interface with Tk. This is no longer the case. Tk has been abstracted into a standalone library (quite some time ago, actually) and Python uses it pretty much the same way Tk does. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Jorge Godoy [EMAIL PROTECTED] writes: Mike Meyer wrote: [ Having GUI stuff included on a standard installation of Python ] However, you can get compilers for both that come bundled with a good GUI library. Could it be that that's what you really want - someone to distribute Python bundled with an enterprise-class GUI library and IDE? And then you are going to have three or four different distributors of Python using three or four different GUI toolkits and also python.org distributing Python for free without any (or with TKinter)... Which one will be the standard distributor so that it gets documented and adopted? We already have multiple distributions of Python: CPython, IronPython, and Jython (and there's at least one more). We even have multiple distributions of CPython, what with Active State doing their own and the MacPython distribution. I'm not proposing a fundamental change in the world, I'm suggesting an addition that would satisify the OPs needs. The standard distributor is whichever one your organization settles on when it comes time to choose a Python distribution. In an international project I see othe problems as well -- cost, logistics, SH, customs, etc. None of which has stopped linux from following this path. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
Paul Rubin http://[EMAIL PROTECTED] writes: The others are non-Pythonic because they're not included in the standard distro and therefore the Pythonic use the included batteries tenet says to use Tkinter despite its flaws. When did use the included batteries become pythonic? import this says nothing about batteries. Nah, using Tkinter is pythonic because practicality beats purity. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: How override ALL function calls? (Is there a function call function?)
[EMAIL PROTECTED] wrote: I'm trying run a homegrown profiler on some Python code. Rather than apply profiler wrapper to ALL functions by hand Is there a low level Python function I can override to modify how ALL functions are called? Yes, please take a look at sys.setprofile(). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple inheritance super()
Michele Simionato [EMAIL PROTECTED] writes: Mike Meyer: I think you're replying to me, but you didn't include any indication so I can't be sure. Oops, sorry, yes, I was replying to you. These two are cases of what I was talking about when I referred to the Church-Turing thesis. Well, let me put it in this way. If a language can implement a missing feature easily, then you are not really missing a big thing. And the feature may not be provided by default for sake of semplicity and/or uniformity of style. For instance Python does not have repeat-until loops, case statement, ternary operator, etc. (obviously I am not advocating to remove multiple inheritance now, I am justing speculating, talking about an hypotetic new Python-like language). Also, I don't see how they make the situation you are scared of above any better. It would discourage some people from some abuses, in the same sense the absence of repeat-until, case statemente, ternary operator etc are working right now. These two points are working at cross purposes. If you can implement a missing feature easily, then it doesn't do much to discourage abuses of that feature. 3. think differently and use multimethods I don't see how that would help at all. You haven't done anything about solving the base problem - that getting the methods into my classes cleanly needs multiple inheritance. Further, I don't need methods that are distinguished based on their arguments - they all take a fixed set of arguments, and operate on them and the state of the instance. None seem to be candidates for being multimethods. The mixin methods tend to provide general functionality, and get used in radically different places by the different child classes. You did miss the one alternative I considered: making the methods of Mixin stand-alone functions, and passing them extra arguments instead of using attributes of the instance. They would all then look like mixin_func(self.foo, self.bar, var, value). I decided that this wasn't as readable as inherting the methods. Uhm? I do not follow you. Multimethods would dispatch according to the type and would act differently on the childrens, dependending on their state. Perhaps I would need more information to understand what you have in mind. Ok, let's take a typical Mixin example. All the classes work with HTML pages rendered as soup. Some of them only deal with one page, others walk through multiple pages to find some specific bit of information. Each of them stores the page it's currently working on in the attribute page. The get_value method of Mixin extracts a string from self.page. You pass it a string, it invokes methods of self.page to locate a string that stands in a fixed relation to the string you passed in to it, and returns the found string. I don't see how this could be made a multimethod. What it does doesn't change depending on selfs type. This example could trivially have been done as a standalone function, as it only uses one attribute. Others use more, say filling out forms based on a dictionary attribute, or some such. But at the end my point is I would not feel much more constrained in expressivity if I did not have multiple inheritance in Python, and actually I have found out that the more I use OOP, the less I use inheritance. Just curious if others had a similar experience. No, and yes. I think that using less inheritance as you get more practice with it is a common thing. At first, it seems very cool, and you're tempted to use it for everything. Then you find the problems that this creates, and back off from it some. On the other hand, as my understanding of inheritance deepened, I found myself using multiple inheritance more, not less. Mostly, it's for mixins. Sometimes, I really do need objects that have multiple types. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wheel-reinvention with Python
On Sun, 2005-07-31 at 14:58 -0400, Mike Meyer wrote: And what do I use to bundle my application for Unix? Most of the things I build get installed on Unix servers. You install GUI apps on Unix *servers*? Regardless, when you say Unix, what do you mean? You may as well say OS as this term has little meaning. Linux (which flavor)? BSD? SCO? HPUX? OS/X? Minix? Whichever way, I suspect that a bit of distutils hacking would solve your problem. Regards, Cliff -- [EMAIL PROTECTED] http://www.develix.com :: Web applications and hosting :: Linux, PostgreSQL and Python specialists :: -- http://mail.python.org/mailman/listinfo/python-list