ANN: java2python 0.1
java2python - Java to Python Source Code Translator --- java2python 0.1 Released 14 February 2007 What is java2python? -- java2python is a simple but effective tool to translate Java source code into Python source code. It's not perfect, and does not aspire to be. Where can I get java2python? -- java2python is available for download from Google code: http://code.google.com/p/java2python/downloads/list Project page: http://code.google.com/p/java2python/ How do I use java2python? -- Like this: $ j2py -i input_file.java -o output_file.py The command has many options, and supports customization via multiple configuration modules. What are the requirements? -- java2python requires Python 2.5 or newer. Previous versions may or may not work. java2python requires ANTLR and PyANTLR to translate code, but translated code does not require ANTLR. What else? -- java2python is installed with distutils. Refer to the Python distutils documentation for more information. The digest version is: $ tar xzf java2python-0.1.tar.gz $ cd java2python-0.1 $ python setup.py install java2python is licensed under the GNU General Public License 2.0. No license is assumed of (or applied to) translated source. I'm very interested in your experience with java2python. Please drop me an note with any feedback you have. Troy Melhase mailto:[EMAIL PROTECTED] pgpexXvQ7ahgm.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Pygments 0.7 Faschingskrapfn released
I'm very pleased to announce the third public release of Pygments, the generic Python syntax highlighter. Download it from http://cheeseshop.python.org/pypi/Pygments, or look at the demonstration at http://pygments.org/demo. News The new features since 0.6 include: * New lexers for * OCaml * Dylan * Java Server Pages * Windows batch files * Trac Wiki markup * Python tracebacks * ReStructuredText * sources.list * Mako templates * and the Befunge esoteric programming language (yay!) * Token stream filters, which can e.g. highlight certain names or code tags. * An HTML formatter that is easily subclassable. * An option to control the command prefix for the LaTeX formatter. * A MoinMoin parser plugin to easily get Pygments highlighting in Moin. * ... and many little changes and fixes that are listed in the detailed changelog. About - Pygments is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code. Highlights are: * a wide range of common languages and markup formats is supported * special attention is paid to details increasing quality by a fair amount * support for new languages and formats are added easily * a number of output formats is available, presently HTML, LaTeX, RTF and ANSI sequences * it is usable as a command-line tool and as a library * ... and it highlights even Brainf*ck! The home page is at http://pygments.org. Read more in the FAQ list http://pygments.org/faq or look at the documentation http://pygments.org/docs. regards and happy Valentine's day, Georg -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Regular Toronto Python User's Group (PyGTA) meeting this Tuesday
As usual we will be holding our PyGTA meeting at the cool and funky Linux Caffe, located at the corner of Grace and Harbord Streets in downtown Toronto. This month's talk will be presented by our own Clifford Ilkay of Dinamis Corporation on using the Django web framework. A framework that Guido himself has described as Pythonic and which has a reasonably large and devoted following in the Python web framework ecosystem. As usual we will begin gathering, picking up delicious drinks and socialising around 6:30 pm, with the formal part of the meeting starting at 7:00pm. We'll head out for beer, ice cream and what have you around 8:30 or 9:00. Maps and the like available on the wiki: http://web.engcorp.com/pygta/wiki/NextMeeting Have fun all, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: EasyDialogs for Windows version 46691.0
EasyDialogs for Windows is available at: http://www.averdevelopment.com/python/ EasyDialogs for Windows is a ctypes based emulation of the EasyDialogs module included in the Python distribution for Mac. It attempts to be as compatible as possible. Code using the Mac EasyDialogs module can often be run unchanged on Windows using this module. The module has been tested on Python 2.3 running on Windows NT, 98, XP, and 2003. EasyDialogs is written in pure Python using Thomas Heller's ctypes module to call Windows APIs directly. No Python GUI toolkit is used. This means that relatively small distributions can be made with py2exe (or its equivalents). A simple test of all the dialogs in EasyDialogs bundled up using py2exe results in a distribution that is about 1.25MB. Using py2exe in concert with NSIS as shown here allows the same test to run as a single file executable that is just under 500KB. Requires: Microsoft Windows, Python 2.3 or higher, and ctypes 0.6.3 or higher (ctypes is included with Python 2.5 and higher, so it is not a separate requirement there). License: MIT Change history: Version 46691.0 - Fixed a bug that caused warnings with newer version of ctypes (including the version included in Python 2.5) - The edit box in AskString now scrolls horizontally if the entered text does not otherwise fit - AskFileForOpen(multiple=True) will allow multiple files to be selected and a list of strings will be returned. If multiple is False (the default if not specified) then only a single file can be selected and a string is returned. This no longer seems to work on the Mac, but it's useful enough to add it to the Windows version anyway. This change is based on a patch contributed by Waldemar Osuch. - Made minor changes to bring inline with SVN revision 46691 for Mac Version 1.16.0 - Removed resource DLL, resources are now in a Python source file which simplifies distribution of apps with py2exe - Spelling corrections - File open/save dialogs did not display on Windows 98 - AskString edit boxes were too short on Windows 98 - Improved display of drop down lists on Windows 98 and NT - Made minor changes to bring inline with CVS version 1.16 for Mac Version 1.14.0 - Initial public release Jimmy -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Method overloading?
On 14 Feb 2007 20:54:31 -0800, placid [EMAIL PROTECTED] wrote: class Test: def __init__(self): pass def puts(self, str): print str def puts(self, str,str2): print str,str2 you might look into the overloading module and its decorator. source is in the sandbox: http://svn.python.org/view/sandbox/trunk/overload/overloading.py using it, you could re-write your example as: # from overloading import overloaded class Test(object): @overloaded def puts(self, S): print S @puts.register(object, str, str) def puts_X(self, S, S2): print S, S2 two things to note. first, i changed your class to derive from object. I don't know if that's required, but i suspect it is. second, i changed your argument names. the argument names in your example shadow built-in names. you shouldn't do that in any case, but it could become especially confusing using the overloaded decorator, which relies on argument type to select the correct method. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to store and still search special characters in Python and MySql
On Feb 12, 12:26 pm, ronrsr [EMAIL PROTECTED] wrote: I have an MySQL database called zingers. The structure is: snip I am having trouble storing text, as typed in latter two fields. Special characters and punctuation all seem not to be stored and retrieved correctly. Special apostrophes and single quotes from Microsoft Word are causing a special problem, even though I have ''ed all 's snip Input and output is through a browser. snip UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 95: ordinal not in range(128) args = ('ascii', update zingers set keywords = 'a;Action;b;Religi... \n \n \n ' where zid = 422, 95, 96, 'ordinal not in range(128)') encoding = 'ascii' end = 96 object = update zingers set keywords = 'a;Action;b;Religi... \n \n \n ' where zid = 422 reason = 'ordinal not in range(128)' start = 95 the characters I am trying to add are startquote and endquote copied and pasted from Microsoft Word. snip http://tinyurl.com/2g9364 as nobody has replied yet...perhaps the above link may help -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
On 2/15/07, James Stroud [EMAIL PROTECTED] wrote: I guess we differ on what is obvious. This seems obvious to me: [1] + (1,) = [1, 1] (1,) + [1] = (1, 1) I agreed with you up to this point. But this seems more obvious to me: [1] + (1,) = [1, 1] (1,) + [1] = [1, 1] In other languages and situations, types are widened, 1 + 1.0 = 1.0 + 1.0. And list is wider than tuple. -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: c++ for python programmers
Nicola Musatti [EMAIL PROTECTED] skriver: On Feb 14, 2:41 pm, Neil Cerutti [EMAIL PROTECTED] wrote: [...] Don't forget the lack of standard garbage collection. memory related problems. I'm aware that most is not the same as all, but on the other hand garbage collection has it's problems too: And that garbabe collection is only good for memory, garbage collecting open files and network connections work much less well. Giving the need to add a maonual delete function to be called before the object is destroed when you need the life time controll. And this having to be reflected in application depenednt way to figure out how it works in each application. / Balp -- http://anders.arnholm.nu/Keep on Balping -- http://mail.python.org/mailman/listinfo/python-list
how do real python programmers work?
_ Wendy Tyrrell WRL Adviser Camden Education Business Partnership Children, Schools and Families London Borough of Camden The Medburn Centre 136 Chalton Street NW1 1RX Streetmap: http://www.streetmap.co.uk/streetmap.dll?G2M?X=529491Y=183342A=YZ=1 Phone: 020 7974 8249 Fax: 020 7383 0875 Mobile: 07815 502 024 e-mail: [EMAIL PROTECTED] Website: www.camden.gov.uk **Volunteer for our Mentoring Programmes** ** Call or email me for details** This e-mail may contain information which is confidential, legally privileged and/or copyright protected. This e-mail is intended for the addressee only. If you receive this in error, please contact the sender and delete the material from your computer -- http://mail.python.org/mailman/listinfo/python-list
Re: threading and multicores, pros and cons
On Feb 14, 4:30 pm, MRAB [EMAIL PROTECTED] wrote: Hmm. I wonder whether it would be possible to have a pair of python cores, one for single-threaded code (no locks necessary) and the other for multi-threaded code. When the Python program went from single- threaded to multi-threaded or multi-threaded to single-threaded there would be a switch from one core to the other. I have explored this option (and some simpler variants). Essentially, you end up rewriting a massive amount of CPython's codebase to change the refcount API. Even all the C extension types assume the refcount can be statically initialized (which may not be true if you're trying to make it efficient on multiple CPUs.) Once you realize the barrier for entry is so high you start considering alternative implementations. Personally, I'm watching PyPy to see if they get reasonable performance using JIT. Then I can start hacking on it. -- Adam Olsen, aka Rhamphoryncus -- http://mail.python.org/mailman/listinfo/python-list
ZSI + mod_python
Hi, I tried for the last 2 hours now to somehow grasp how to use ZSI over mod_python. It's nice that they have a code-example in the ZSI docs, but it's incomplete and you are left guessing. The ZSI docs I used as reference can be found on http:// pywebsvcs.sourceforge.net/zsi.html#SECTION00313 Here is where I am at so far: First I created the two files as described in the ZSI docs. Namely MyHandler.py and ws.py. The first name is obvious to someone who has coded at least a little bit of python, but it could be explicitly stated in the docs, so the beginners don't get stumped by a silly filename to start with ;) The second filename is my own concoction. I suppose it does not matter how it's named as you specify it in the apache conf anyhow. So. Now to the apache conf. I put the scripts into the document-root of my server. In this case: /var/www/localhost. So this is what I get (ommitting the unnecessary cruft -- marked it with [...]): /etc/apache2/sites-enables/000-default.conf --- VirtualHost * [...] DocumentRoot /var/www/localhost AddHandler mod_python .py [...] Directory /var/www/localhost/ [...] PythonHandler ws PythonDebug On /Directory [...] This is as far as I got. Now how do I call a service from this setting? What's the URI I need to specify in the client? I was trying http://server/foo.py; in the browser, and it was obviously doing *something* with the ws.py file. But I have no clue what. Here's the output: Browser output for http://server/foo.py - Mod_python error: PythonHandler ws Traceback (most recent call last): File /usr/lib/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch result = object(req) File /var/www/localhost/ws.py, line 9, in handler dispatch.AsHandler(modules=(MyHandler,), request=req) File /usr/lib/python2.4/site-packages/ZSI-2.0_rc3-py2.4.egg/ZSI/ dispatch.py, line 263, in AsHandler File /usr/lib/python2.4/site-packages/ZSI-2.0_rc3-py2.4.egg/ZSI/ parse.py, line 61, in __init__ File /usr/lib/python2.4/site-packages/PyXML-0.8.4-py2.4-linux- i686.egg/_xmlplus/dom/ext/reader/PyExpat.py, line 65, in fromStream success = self.parser.ParseFile(stream) ExpatError: no element found: line 1, column 0 No matter what I append to the URI, it does not make a difference in the output. And *why* am I forced to add a abracadabra.py to the URI? Could I not set Apache up in a way that it would use the ZSI handler for everything that calls -- let's say -- http:// webservices.server.tld/ instead of http://webservices.server.tld/ booh.py ? I'm off to a little bit more of testing. But any hints/input would be kindly appreciated ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: how do real python programmers work?
Tyrrell, Wendy wrote: (Well, nothing) Was that all your question, Wendy, or did you accidentally hit the Send button too soon? You're welcome to ask here or on the tutor list http://mail.python.org/mailman/listinfo/tutor if you want to find out about Python. Or just look at the website: http://python.org Your organisation seems to deal with partnerships between business and education; are you looking to promote the use of programming in schools? Or is there something else you're after? (I'm above-averagely curious because I work in Camden and I'm involved in Youth work in Ealing). Tim Golden -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: py lib 0.9.0: py.test, distributed execution, microthreads ...
holger krekel wrote: ... * py.execnet: ad-hoc code distribution to SSH, Socket and local sub processes ... Good stuff, but my rather ancient win32 client could not work properly with SshGateway; I think plink might work. I hacked register.py so that the eventual command came out something like plink -ssh MYSESSION python -u -c 'exec input()' and then I can get a gateway open at least. The following script then works on my win32 box from py.execnet import SshGateway gw = SshGateway('MYSESSION',remotepython='python25') channel = gw.remote_exec('channel.send(Hello From the remote world!)') print channel.receive() and I see C:\tmp\tmp\tgw.py Hello From the remote world! C:\tmp -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
ANN: EasyDialogs for Windows version 46691.0
EasyDialogs for Windows is available at: http://www.averdevelopment.com/python/ EasyDialogs for Windows is a ctypes based emulation of the EasyDialogs module included in the Python distribution for Mac. It attempts to be as compatible as possible. Code using the Mac EasyDialogs module can often be run unchanged on Windows using this module. The module has been tested on Python 2.3 running on Windows NT, 98, XP, and 2003. EasyDialogs is written in pure Python using Thomas Heller's ctypes module to call Windows APIs directly. No Python GUI toolkit is used. This means that relatively small distributions can be made with py2exe (or its equivalents). A simple test of all the dialogs in EasyDialogs bundled up using py2exe results in a distribution that is about 1.25MB. Using py2exe in concert with NSIS as shown here allows the same test to run as a single file executable that is just under 500KB. Requires: Microsoft Windows, Python 2.3 or higher, and ctypes 0.6.3 or higher (ctypes is included with Python 2.5 and higher, so it is not a separate requirement there). License: MIT Change history: Version 46691.0 - Fixed a bug that caused warnings with newer version of ctypes (including the version included in Python 2.5) - The edit box in AskString now scrolls horizontally if the entered text does not otherwise fit - AskFileForOpen(multiple=True) will allow multiple files to be selected and a list of strings will be returned. If multiple is False (the default if not specified) then only a single file can be selected and a string is returned. This no longer seems to work on the Mac, but it's useful enough to add it to the Windows version anyway. This change is based on a patch contributed by Waldemar Osuch. - Made minor changes to bring inline with SVN revision 46691 for Mac Version 1.16.0 - Removed resource DLL, resources are now in a Python source file which simplifies distribution of apps with py2exe - Spelling corrections - File open/save dialogs did not display on Windows 98 - AskString edit boxes were too short on Windows 98 - Improved display of drop down lists on Windows 98 and NT - Made minor changes to bring inline with CVS version 1.16 for Mac Version 1.14.0 - Initial public release Jimmy -- http://mail.python.org/mailman/listinfo/python-list
ANN: java2python 0.1
java2python - Java to Python Source Code Translator --- java2python 0.1 Released 14 February 2007 What is java2python? -- java2python is a simple but effective tool to translate Java source code into Python source code. It's not perfect, and does not aspire to be. Where can I get java2python? -- java2python is available for download from Google code: http://code.google.com/p/java2python/downloads/list Project page: http://code.google.com/p/java2python/ How do I use java2python? -- Like this: $ j2py -i input_file.java -o output_file.py The command has many options, and supports customization via multiple configuration modules. What are the requirements? -- java2python requires Python 2.5 or newer. Previous versions may or may not work. java2python requires ANTLR and PyANTLR to translate code, but translated code does not require ANTLR. What else? -- java2python is installed with distutils. Refer to the Python distutils documentation for more information. The digest version is: $ tar xzf java2python-0.1.tar.gz $ cd java2python-0.1 $ python setup.py install java2python is licensed under the GNU General Public License 2.0. No license is assumed of (or applied to) translated source. I'm very interested in your experience with java2python. Please drop me an note with any feedback you have. Troy Melhase mailto:[EMAIL PROTECTED] pgpf4KzxBwnWd.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception
Navid Parvini wrote: Dear All, Would you please tell me if there is a pysignal or method that called when an exception is occurred? (I don't want to use try method) No such method exists, and signals aren't used to generate exceptions. I'm afraid you want some other language, not Python. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: c++ for python programmers
Anders Arnholm wrote: Sam [EMAIL PROTECTED] skriver: On 13 Feb 2007 17:51:00 GMT, Jorgen Grahn [EMAIL PROTECTED] wrote: Well, C++ is a better language than C in many ways. So, if he needs to learn one of them, why does it have to be C? Another reason some people choose C++ over Python for some tasks is that they feel that larger programs benefit from strong, static type checking. I like both ways, but depending on the task, one or the other is better. C++ is -not- strongly typed. You can cast anything to void *, and manipulate it in ways unimaginable. Plus there's the whole mess that is pointer arithmetic and a weak typesystem... C++ can be both, The type systenm is as fragila as you like it to be. I mainlty use c++ when i the need stronger typing that Python och C can't give me. In some ways it's even stronger types than languanges as Java and ObjectiveC. C++ it however at least four different languanges, in one ball of soupe. Presuming when i the need is a typo for when I need the rather than when i feel the need for, when do you actually *need* strong typing? By which I presume you to mean status typing, since Python is already a strongly-types language. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: rot13 in a more Pythonic style?
On 14 Feb, 21:59, Paul Rubin http://[EMAIL PROTECTED] wrote: Why don't you describe the actual problem instead of the rot13 analogy. I don't know what the actual problem is! I need to perform a complex mapping between old style structured identifiers and new style structured identifers. As the original specification was never thought through or written down anywhere, I'm now having to try and reverse- engineer from 5 years of collected inconsistent practice. So far I have about four pages of BNF to describe things and I'm still not sure what's accurate, what's inaccurate spec and what's merely an error in practice. Hopefully there's a neat little structure underlying it all and a few typos I can merely ignore, but probably it really is just an inconsistent structure that needs a lot of explicit tests around the corner-cases to make sense of. rot13 isn't the issue here, and I already know how to use .translate() What I'm after is a tutorial of my Python coding style for an example that's quite similar to the rot13 case. Your previous posting was very helpful here. -- http://mail.python.org/mailman/listinfo/python-list
Re: hi all
Sandeep Patil , Bangalore wrote: I get an error while I try to call python through VB. The error is “ Error 429: Active X cant create object” Pls anybody help me to call python through VB. The problem is on line 23 of your code. Sorry, that was a rather flip way of saying that without seeing some actual code it's very difficult to know what will help. Do you get a Python stack traceback? If so that would also help. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: threading and multicores, pros and cons
On 15 Feb, 00:14, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Yeah, it's the Window equivalent to fork. Does true copy-on-write, so you can do efficient multiprocess work. Aside from some code floating around the net which possibly originates from some book on Windows systems programming, is there any reference material on ZwCreateProcess, is anyone actually using it as fork on Windows, and would it be in any way suitable for an implementation of os.fork in the Python standard library? I only ask because there's a lot of folklore about this particular function (everyone seems to repeat more or less what you've just said), but aside from various Cygwin mailing list threads where they reject its usage, there's precious little information of substance. Not that I care about Windows, but it would be useful to be able to offer fork-based multiprocessing solutions to people using that platform. Although the python-dev people currently seem more intent in considering (and now hopefully rejecting) yet more syntax sugar [1], it'd be nice to consider matters seemingly below the python-dev threshold of consideration and offer some kind of roadmap for convenient parallel processing. Paul [1] http://mail.python.org/pipermail/python-dev/2007-February/070939.html -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
James Stroud wrote: [EMAIL PROTECTED] wrote: Concatenating tuples and lists seems logical if you think of tuples as sequences. If you think of them more like Pascal records or C structs instead (I believe that's Guido's perspective on tuples) then it makes no sense at all. Skip Then iterating over them makes no sense? Given Guido's assertions about the nature of the tuple, no it doesn't. But I seriously doubt that 3.0 will remove the iterable interface from tuples, despite its impurity. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question
Stef Mientki wrote: [EMAIL PROTECTED] wrote: On 9 fév, 14:06, Stef Mientki [EMAIL PROTECTED] wrote: will explain the rest Delphi is a (dying) proprietary, MS-Windows-only[1] software relying on a low-level language. Well it may be dying, but for the moment it beats Python with a factor of 10, when it comes to user (the majority of PC users) friendly GUI ;-) Would you mind explaining yourself and backing your above assertion ? Like, ie, on which points does Delphi beats Python wrt/ GUIs, what special magic would make so that GUIs designed with Delphi would be more user-friendly, and where does this factor 10 comes from ? Maybe I should have written it in quotes factor of 10 ;-) But here are a few points - in Delphi the GUI design itself is done in a graphical environment, making it much easier and faster Of course. You are comparing a Pascal-based IDE to a programming language. You might as well say Visual Studio is better than C. [...] but to be honest ... ... I never even tried to write a GUI in Python, ... ... just looked at others examples, ... and still not seen what I can perform in Delphi ;-) Ignorance is bliss. This would apparently make you a troll. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
BJörn Lindqvist wrote: On 2/15/07, James Stroud [EMAIL PROTECTED] wrote: I guess we differ on what is obvious. This seems obvious to me: [1] + (1,) = [1, 1] (1,) + [1] = (1, 1) I agreed with you up to this point. But this seems more obvious to me: [1] + (1,) = [1, 1] (1,) + [1] = [1, 1] In other languages and situations, types are widened, 1 + 1.0 = 1.0 + 1.0. And list is wider than tuple. They are widened by information content, not functionality. Tuples don't have any more information content than lists. -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
Steven D'Aprano wrote: On Wed, 14 Feb 2007 22:21:43 -0800, James Stroud wrote: The user's expected behaviour for [1] + (1,) might be to return a list, or it might be to return a tuple. Since there is no obviously correct behaviour, the right thing to do is to refuse to guess. I guess we differ on what is obvious. This seems obvious to me: [1] + (1,) = [1, 1] (1,) + [1] = (1, 1) simply becuase the operand on the left should take precendence because its __add__ is called and its __add__ returns a list. But that's data dependent. When you call [1] + MyTuple(1) your MyTuple.__radd__ will be called first, not the list's __add__. OK. With this you are beginning to convince me. Yes, I would want my __radd__ called in this case (which is a form of mind-reading, but necessary and convenient)--so your point is how might python read one's mind given list and tuple. You got me there. But you must agree that I am not an easy turn. -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame and python 2.5
[EMAIL PROTECTED] wrote: On Feb 13, 2:24 am, Steve Holden [EMAIL PROTECTED] wrote: [...] This wouldn't be a simple project, but since there's a Windows buildbot for Python there's no reason why the same couldn't be done for extensions. I'll raise this with the PSF and see what the response is: then your carping will at least have had some positive effect ;-) Stick with it, and let's try to make things better. Ok. On a point of information, as it happens there's a Board meeting today and I have tabled the topic for discussion. Unfortunately I can't guarantee to attend the meeting (I am moving from the UK to the USA this week) but I will try to do so, and will attempt to report back to c.l.py within a week. Again, thanks for listening and trying to help. Even if nothing comes of it, at least we tried. I figure that sooner or later something has to be done and I'd rather see it done sooner. And no, I don't think I'm entitled to that. regards Steve Unfortunately the matter wasn't discussed due to my enforced absence from the 'Net and pressure of other business. But it's on my radar now and I will continue to progress it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
Paul McGuire wrote: Since tuples are immutable, I think of them as fixed data objects with some simple sequential structure, as opposed to lists which are much more dynamically accessible/updateable data containers. Back in my relational database design days, I sometimes had to create a primary key for a table by combining values stored in two or more columns - neither column value alone was unique, but the combination of them was, and so made a good retrieval index. In Python, such data pairs would be ideally represented with tuples, in support of in-memory data cacheing or tree indexing - for a given record, the values don't change, so the immutability of their tupleness doesn't get in the way. In similar vein, I've used tuples internally in my Python code as cache keys for function memoizing. They are WORM structures - write once, read many - built to represent the cache value, but never updated. With this idea of tuples as a data structure, I could reasonably interpret this: (1,abc,3) + [1] to result in (1,abc,3,[1]) just as well as (1,abc,3,1). But instead of just picking one, Python complains about this, and so forces me to explicitly use (1,abc,3) + tuple([1]) or (1,abc,3) + ([1],) I don't think tuples are just an academic curiosity, as your post seems to suggest. -- Paul Were lists implemented as efficiently as tuples in terms of memory and speed, there would be no difference except the academic one--which is perhaps important. Actually, I must admit that I use them and their implicit meanings all the time in my code (as proof, notice in the any way to create a table-like object? thread how I specify column headers--its for a reason I use tuple in the example because the resulting data structures will be ordered according to the tuple passed--of course, I refuse to enforce this via ugly and boring type checking). For the most part, I ignore the implementation differences and draw the distinction at their semantics. Also, risking getting a reputation for being overly contentious, I think your argument falls apart in the latter half of your post because +, as far as I can tell with python sequences, is used to mean catenate exclusively and not append, which is what you suggest as a possibility. Anyway, D'Arpano made an excellent point with a good mind-reading example and so I understand the design decision regarding catenation of tuples and lists more clearly now. I'm still not sure I like it, but there is no accounting for taste. James -- http://mail.python.org/mailman/listinfo/python-list
Re: How much memory used by a name
Bernard Lebel wrote: Bruno: good question. We're talking about text files that can have 300,000 lines, if not more. Currently, the way I have coded the file writing, every line calls for a write() to the file object, which in turns write to the text file. The file is on the network. assuming an average line length of 30 (for program code) to 60-80 characters (for human text), that's no more than 12-24 megabytes of data. few modern computers should have any trouble holding that in memory. just build the list in memory, and use a single writelines call to write everything to disk. (alternatively, try write(.join(data)). that'll use twice as much memory, but may be a little bit faster) This is taking a long time, and I'm looking for ways to speed up this process. I though that keeping the list in memory and dropping to the file at the very end could be a possible approach. chances are that you're already I/O bound, though... /F -- http://mail.python.org/mailman/listinfo/python-list
basic jython question
Hello all I have a 'logger' module which is essentially just a facade over the 'logging' standard module. Can this be called from jython, and how is this acheived? This is a colleague's question but I have no knowledge of jython or java, and I can't install them at present in order to figure it out. It appears that the CPython logging builtin is not implemented in Jython, is this correct? The source for CPython's logging says that it should work with Python 1.5.2, so given everything from Python2.4/Lib/Logging and my own facade module, is there any way to get it working from a jython script? I presume they just can't be dropped in to a site-packages directory? I'm completely in the dark, any help? Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: A problem of using pyfort
I didn't find any solutions via internet. So I really need your help. The OS on my computer is Fedora Core 5. Thanks in advance. Really? Entering the error-message and fedora core 5 brings this up as first result in google: http://www.bo.infn.it/alice/alice-doc/mll-doc/ali-inst/node40.html So - you certainly need to improve your googling-skillz. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: basic jython question
Gerard Flanagan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a 'logger' module which is essentially just a facade over the 'logging' standard module. Can this be called from jython, and how is this acheived? This is a colleague's question but I have no knowledge of jython or java, and I can't install them at present in order to figure it out. Since the CPython module is heavily influenced by the native Java logging framework (and/or log4j), I would have thought that it would be easier to create a Jython wrapper for those. -- http://mail.python.org/mailman/listinfo/python-list
Re: Method overloading?
On 15 fév, 09:32, Troy Melhase [EMAIL PROTECTED] wrote: On 14 Feb 2007 20:54:31 -0800, placid [EMAIL PROTECTED] wrote: class Test: def __init__(self): pass def puts(self, str): print str def puts(self, str,str2): print str,str2 you might look into the overloading module and its decorator. source is in the sandbox: http://svn.python.org/view/sandbox/trunk/overload/overloading.py Or have a look at Philip Eby's dispatch package, which is kind of overloading on steroids... -- http://mail.python.org/mailman/listinfo/python-list
Re: AUX File Writing Error
En Thu, 15 Feb 2007 03:34:59 -0300, John Machin [EMAIL PROTECTED] escribió: On Feb 15, 4:03 pm, [EMAIL PROTECTED] wrote: Is there any way I can create an AUX.csv file without the error? Probably not. AUX, CON, NUL, PRN, LPT, COM1, COM2 etc (with or without an extension) are reserved in Windows for specific devices for compatibility with MS-DOS 1.00 programs, which did that for compatibility with CP/M. (This is OT now) Do you know why AUX.csv is invalid too? I can accept that AUX (without extension) is an invalid filename, but it is quite different from AUX.csv -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: AUX File Writing Error
Gabriel Genellina wrote: En Thu, 15 Feb 2007 03:34:59 -0300, John Machin [EMAIL PROTECTED] escribió: On Feb 15, 4:03 pm, [EMAIL PROTECTED] wrote: Is there any way I can create an AUX.csv file without the error? Probably not. AUX, CON, NUL, PRN, LPT, COM1, COM2 etc (with or without an extension) are reserved in Windows for specific devices for compatibility with MS-DOS 1.00 programs, which did that for compatibility with CP/M. (This is OT now) Do you know why AUX.csv is invalid too? I can accept that AUX (without extension) is an invalid filename, but it is quite different from AUX.csv Because Windows is brain-dead? There really is no sense in looking for rationality where none exists. This is the way it is, and there's nothing you can do about it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: How much memory used by a name
On Feb 14, 9:41 pm, Bernard Lebel [EMAIL PROTECTED] wrote: This is taking a long time, and I'm looking for ways to speed up this process. I though that keeping the list in memory and dropping to the file at the very end could be a possible approach. It seems, that you're trying to reinvent wheel. Why don't you just use g'old mmap()? http://docs.python.org/lib/module-mmap.html -- http://mail.python.org/mailman/listinfo/python-list
Re: basic jython question
On Feb 15, 1:53 pm, Richard Brodie [EMAIL PROTECTED] wrote: Gerard Flanagan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a 'logger' module which is essentially just a facade over the 'logging' standard module. Can this be called from jython, and how is this acheived? This is a colleague's question but I have no knowledge of jython or java, and I can't install them at present in order to figure it out. Since the CPython module is heavily influenced by the native Java logging framework (and/or log4j), I would have thought that it would be easier to create a Jython wrapper for those. Ok, thanks. I'll suggest that. Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: list of range of floats
On Feb 14, 6:12 pm, Steve [EMAIL PROTECTED] wrote: I'm trying to create a list range of floats and running into problems. I've tried it the easy way. Works. map(float,range(a,b)) -- http://mail.python.org/mailman/listinfo/python-list
Re: AUX File Writing Error
On Feb 16, 12:13 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 15 Feb 2007 03:34:59 -0300, John Machin [EMAIL PROTECTED] escribió: On Feb 15, 4:03 pm, [EMAIL PROTECTED] wrote: Is there any way I can create an AUX.csv file without the error? Probably not. AUX, CON, NUL, PRN, LPT, COM1, COM2 etc (with or without an extension) are reserved in Windows for specific devices for compatibility with MS-DOS 1.00 programs, which did that for compatibility with CP/M. (This is OT now) Do you know why AUX.csv is invalid too? I can accept that AUX (without extension) is an invalid filename, but it is quite different from AUX.csv It is actually a valid file name, but the file is not on disk. I presume that the OP got an error because it was in 'a' (append) mode which requires an existing disk file. See below. C:\junkcopy con aux.csv fubar ^Z 1 file(s) copied. C:\junkcopy con sux.csv fubar ^Z 1 file(s) copied. C:\junkdir *ux.csv [snip] Directory of C:\junk 16/02/2007 01:19 AM 7 sux.csv 1 File(s) 7 bytes Why? Who knows? We're talking CP/M, MS-DOS and Windows and you want to know why? Probably too lazy to distinguish between 'AUX\0', 'AUX.\0' and 'AUX.XYZ\0' ... probably stopped scanning on reaching the first invalid character. If you're desperate to find out, dial up your nearest RCPM and ask the sysop :-) Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: AUX File Writing Error
On Thu, 15 Feb 2007 10:13:17 -0300, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 15 Feb 2007 03:34:59 -0300, John Machin [EMAIL PROTECTED] escribió: On Feb 15, 4:03 pm, [EMAIL PROTECTED] wrote: Is there any way I can create an AUX.csv file without the error? Probably not. AUX, CON, NUL, PRN, LPT, COM1, COM2 etc (with or without an extension) are reserved in Windows for specific devices for compatibility with MS-DOS 1.00 programs, which did that for compatibility with CP/M. (This is OT now) Do you know why AUX.csv is invalid too? I can accept that AUX (without extension) is an invalid filename, but it is quite different from AUX.csv Many programs unconditionally add an extension to a filename received from user input or elsewhere. To simplify dealing with files, the open call accounts for this case, assuming that the program did not really want to open a file on disk, but that it just accidentally added an extension where one was not really necessary. There /is/ a way to open an on-disk file named AUX or AUX.csv, but it requires special spelling. I don't remember the details at present, but presumably if you are interested you can dig it up on MSDN. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
On 15 feb, 07:21, James Stroud [EMAIL PROTECTED] wrote: I guess we differ on what is obvious. This seems obvious to me: [1] + (1,) = [1, 1] (1,) + [1] = (1, 1) simply becuase the operand on the left should take precendence because its __add__ is called and its __add__ returns a list. In essence, as we know the obviously correct behavior for __add__ and __radd__, then it would be the obviously correct behavior that the above would follow. Given those obviouses, the following seems to me: [1] + (1,) = [1, (1,)] That's the trouble with obvious -- my obvious may not be so obvious to you (and vice versa). That's why the Zen of Python says In the face of ambiguity, refuse the temptation to guess. (Although it also says Flat is better than nested, but I'll ignore that for now.) Basically -- if you want Perl, you know where to find it ;-) Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: AUX File Writing Error
En Thu, 15 Feb 2007 11:34:53 -0300, John Machin [EMAIL PROTECTED] escribió: Probably not. AUX, CON, NUL, PRN, LPT, COM1, COM2 etc (with or without an extension) are reserved in Windows for specific devices for compatibility with MS-DOS 1.00 programs, which did that for compatibility with CP/M. (This is OT now) Do you know why AUX.csv is invalid too? I can accept that AUX (without extension) is an invalid filename, but it is quite different from AUX.csv It is actually a valid file name, but the file is not on disk. I presume that the OP got an error because it was in 'a' (append) mode which requires an existing disk file. See below. C:\junkcopy con aux.csv fubar ^Z 1 file(s) copied. The above gives me an Access denied error; perhaps because AUX is my serial port and it is currently in use. Why? Who knows? We're talking CP/M, MS-DOS and Windows and you want to know why? Probably too lazy to distinguish between 'AUX\0', 'AUX.\0' and 'AUX.XYZ\0' ... probably stopped scanning on reaching the first invalid character. If you're desperate to find out, dial up your nearest RCPM and ask the sysop :-) A... I think you hit the point, indirectly. On CP/M the filename was not stored as 'AUX\0' - remember, ONLY 8 characters plus 3 for extension, and NO PATH. A FileControlBlock (FCB) had exactly 11 characters reserved for the file name (plus the drive number). So it was actually AUX vs AUX XYZ and... well, the lazyness argument again. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
list of strings-newline
Hi i have a list as follows list=a1,b1,c1,d1,a2,b2,c2,d2,a3,b3,c3,d3, I would like to print as a1,b1,c1,d1, a2,b2,c2,d2, a3,b3,c3,d3, and then i would like to delete the comma at the end,,say like,, a1,b1,c1,d1 a2,b2,c2,d2 a3,b3,c3,d3 (its always after the length is 4 i would like to write as the next line) if any one has any suggestions pls write to me,, - Heres a new way to find what you're looking for - Yahoo! Answers -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin set literal
Schüle Daniel wrote: Hello, lst = list((1,2,3)) lst = [1,2,3] t = tupel((1,2,3)) t = (1,2,3) s = set((1,2,3)) s = ... it would be nice feature to have builtin literal for set type maybe in P3 .. what about? s = 1,2,3 In Python 3.0, this looks like:: s = {1,2,3} More info here: http://www.python.org/dev/peps/pep-3100/ STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: threading and multicores, pros and cons
Maric Le mercredi 14 février 2007 16:24, [EMAIL PROTECTED] a écrit : Some time back, a group did remove the GIL from the python core, and implemented locks on the core code to make it threadsafe. Well, the problem was that while it worked, the necessary locks it made single threaded code take significantly longer to execute. Maric Very interesting point, this is exactly the sort of thing I'm Maric looking for. Any valuable link on this ? Google for python free threading stein then click the first link. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
Sergey posix.stat_result is CLASS, not regular tuple. I believe it morphed from being a tuple though. I wasn't suggesting that there is some other way to approximate records. I was trying to demonstrate the use of a tuple as a record. It eventually became so compelling that a new struct_time type was created. It works both like a tuple as a class. The notion of tuples as records in Python is not new: http://mail.python.org/pipermail/python-list/1999-December/thread.html Search for super tuples. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Method overloading?
On 2007-02-15, placid [EMAIL PROTECTED] wrote: Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str def puts(self, str,str2): print str,str2 if __name__ == __main__: t = Test() t.puts(hi) t.puts(hi,hello) You tell us: what happened when you tried it? Well, when i run it i get this error puts() takes exactly 3 arguments (2 given) which means that the second a time i try to define the puts() method overwrites the first one Correct. That means it's not possible to do what you wrote. And then what happens when you do this? class Test: def __init__(self): pass def puts(self, *args): print ' '.join(args) if __name__ == __main__: t = Test() t.puts(hi) t.puts(hi,hello) but this isn't overloading. No, it isn't. [You can't overload methods in Python. Was that your question?] It is, however, the way one does what you appear to be trying to do. -- Grant Edwards grante Yow! If I am elected no at one will ever have to do visi.comtheir laundry again! -- http://mail.python.org/mailman/listinfo/python-list
Re: output to console and to multiple files
On Feb 14, 5:10 pm, goodwolf [EMAIL PROTECTED] wrote: like this? class Writers (object): def __init__(self, *writers): self.writers = writers def write(self, string): for w in self.writers: w.write(string) def flush(self): for w in self.writers: w.flush(): import sys logfile = open('log.txt', 'w') sys.stdout = Writers(aya.stdout, file('log.out', 'w'), logfile) sys.stderr = Writers(aya.stdout, file('log.err', 'w'), logfile) i've tried simliar methods to this and to what Matimus wrote. I know it works great when using print statements. However, I'm looking to find something that will work with the output from a subprocess, such as from spawn, os.system, os.popen, etc. -- http://mail.python.org/mailman/listinfo/python-list
filecmp.cmp() cache
Hello! I have a question about filecmp.cmp(). The short code snippet blow does not bahave as I would expect: import filecmp f0 = foo.dat f1 = bar.dat f = open(f0, w) f.write(1:2) f.close() f = open(f1, w) f.write(1:2) f.close() print cmp 1: + str(filecmp.cmp(f0, f1, False)) f = open(f1, w) f.write(2:3) f.close() print cmp 2: + str(filecmp.cmp(f0, f1, False)) I would expect the second comparison to return False instead of True. Looking at the docs for filecmp.cmp() I found the following: This function uses a cache for past comparisons and the results, with a cache invalidation mechanism relying on stale signatures.. I guess that this is the reason for my test case failing. Is there someone here that can tell me how I should invalidate this cache? If that is not possible, what workaround could I use? I guess that I can write my own file comparison function, but I would not like to have to do that since we have filecmp. Any ideas? Regards, Mattias -- http://mail.python.org/mailman/listinfo/python-list
Re: rot13 in a more Pythonic style?
On Feb 14, 11:46 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Feb 2007 14:04:17 -0300, Andy Dingley [EMAIL PROTECTED] escribió: I still don't understand what a lambda is _for_ in Python. I know what they are, I know what the alternatives are, but I still haven't found an instance where it permits something novel to be done that couldn't be done otherwise (if maybe not so neatly). A lambda is a shorthand for a simple anonymous function. Any lambda can be written as a function: lambda args: expression is the same as: def __anonymous(args): return expression (but the inverse is not true; lambda only allows a single expression in the function body). Except for easy event binding in some GUIs, deferred argument evaluation, and maybe some other case, the're not used much anyway. Prior common usage with map and filter can be replaced by list comprehensions (a lot more clear, and perhaps as fast - any benchmark?) -- Gabriel Genellina They are still useful for reduce(), which has no listcomp equivalent that I know of. -- http://mail.python.org/mailman/listinfo/python-list
Re: output to console and to multiple files
On Feb 14, 6:52 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Feb 2007 19:28:34 -0300, [EMAIL PROTECTED] [EMAIL PROTECTED] escribió: I'm looking for a way to output stdout/stderr (from a subprocess or spawn) to screen and to at least two different files. Look at the tee command. If you control the subprocess, and it's written in Python, using the Python recipes would be easier and perhaps you have more control. But if you can't modify the subprocess, you'll have to use tee. -- Gabriel Genellina Tee, the unix function? Or is there a tee that is python? -- http://mail.python.org/mailman/listinfo/python-list
The Python interactive interpreter has no command history
Hello, How to configure Python2.5's interactive interpreter to get command history ? I always got ^[[A and ^[[B . Thank you !! Thomas# -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
On 2007-02-14, Farshid Lashkari [EMAIL PROTECTED] wrote: Szabolcs Nagy wrote: L=[1] L.extend((1,)) L [1, 1] Are list.extend() and list concatenation supposed to behave differently? I always thought concatenation was just shorthand for calling extend(). They are different. list.extend() mutates the list, returning None, while the + operator returns a new, concatenated list. += on the other hand works very similarly to list.extend(). However: [1, 2].extend([3]) [1, 2] += [3] SyntaxError: augmented assign to list literal or comprehension not possible It seems like the '+' operator for lists should accept any iterable for the right side argument to be consistent with extend() and the '+=' operator. += will only perform the operation in place whenever possible, so there are objects for which a conversion to .extend wouldn't work, and you'd get an actual call of the + operation followed by the assignment operation. -- Neil Cerutti I don't know what to expect right now, but we as players have to do what we've got to do to make sure that the pot is spread equally. --Jim Jackson -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
On 2007-02-15, Paul McGuire [EMAIL PROTECTED] wrote: Since tuples are immutable, I think of them as fixed data objects with some simple sequential structure, as opposed to lists which are much more dynamically accessible/updateable data containers. Me, too. There are plenty of things that aren't strictly a sequence, but which you sometimes want to iterate over anyhow. If I had a set of fast, overpriced luxury cars in my garage, I would sometimes want to do something to each one (like wash them), even though they really aren't in any sequence. Dictionary keys are the same sort of thing. Even though they aren't in any sequence, it's still useful to iterate over them. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Method overloading?
On 2007-02-15, Steven D'Aprano [EMAIL PROTECTED] wrote: def multiAccept( argOfVariousTypes ): if isinstance(argOfVariousTypes,int): # treat like an int elif isinstance(argOfVariousTypes,float): # treat like a float elif isinstance(argOfVariousTypes,(list,tuple)): # treat like a container Is that really called overloading? I've never (knowingly) come across the term being used in that context before. I've always known that as multiple dispatch or polymorphism, depending on whether you or the compiler handles the dispatching. It's due to vague terminology that we're using. What the OP wanted to know about was static polymorphism of names based on function signatures, often refered to informally in the context of C++ as function overloading, though it's really identifier overloading where identifier refers to a function or member function. What Python provides is dynamic polymorphism of names with single-dispatch. I think. ;-) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive calls and stack
On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Feb 2007 10:41:53 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: So the effect is that mutual recursion isn't actually any harder. But some kind of language support is required in this case. At least I don't know how to handle mutual recursion (apart from inlining one function inside the other...). But I'm certainly not a program transformation guru (neither a novice!) so I would not be surprised if someone says it can be done... What happens (using the model of an imaginary virtual machine, perhaps like the Python interpreter) is the following. A normal function call pushes a call-frame onto a stack. The call-frame contains information necessary for returning from the function, and usually a place to store its local variables and parameters. A function called in tail position simply overwrites the current call-frame with the new one instead of pushing it onto the stack. -- Neil Cerutti The church will host an evening of fine dining, superb entertainment, and gracious hostility. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list
Re: output to console and to multiple files
On Feb 15, 7:53 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Feb 14, 5:10 pm, goodwolf [EMAIL PROTECTED] wrote: like this? class Writers (object): def __init__(self, *writers): self.writers = writers def write(self, string): for w in self.writers: w.write(string) def flush(self): for w in self.writers: w.flush(): import sys logfile = open('log.txt', 'w') sys.stdout = Writers(aya.stdout, file('log.out', 'w'), logfile) sys.stderr = Writers(aya.stdout, file('log.err', 'w'), logfile) i've tried simliar methods to this and to what Matimus wrote. I know it works great when using print statements. However, I'm looking to find something that will work with the output from a subprocess, such as from spawn, os.system, os.popen, etc. I think you should be able to use my or goodwolf's solution with the subprocess module. Something like this (untested): [code] class TeeFile(object): def __init__(self,*files): self.files = files def write(self,txt): for fp in self.files: fp.write(txt) if __name__ == __main__: import sys from subprocess import Popen command = whatever you want to run outf = file(log.out,w) errf = file(log.err,w) allf = file(log.txt,w) Popen( command, stdout = TeeFile(sys.__stdout__,outf,allf), stderr = TeeFile(sys.__stderr__,errf,allf) ) [/code] -- http://mail.python.org/mailman/listinfo/python-list
Re: filecmp.cmp() cache
Mattias Brändström wrote: I have a question about filecmp.cmp(). The short code snippet blow does not bahave as I would expect: import filecmp f0 = foo.dat f1 = bar.dat f = open(f0, w) f.write(1:2) f.close() f = open(f1, w) f.write(1:2) f.close() print cmp 1: + str(filecmp.cmp(f0, f1, False)) f = open(f1, w) f.write(2:3) f.close() print cmp 2: + str(filecmp.cmp(f0, f1, False)) I would expect the second comparison to return False instead of True. Looking at the docs for filecmp.cmp() I found the following: This function uses a cache for past comparisons and the results, with a cache invalidation mechanism relying on stale signatures.. I guess that this is the reason for my test case failing. Is there someone here that can tell me how I should invalidate this cache? If that is not possible, what workaround could I use? I guess that I can write my own file comparison function, but I would not like to have to do that since we have filecmp. Any ideas? You can clear the cache with filecmp._cache = {} as a glance into the filecmp module would have shown. If you don't want to use the cache at all (untested): class NoCache: def __setitem__(self, key, value): pass def get(self, key): return None filecmp._cache = NoCache() Alternatively an update to Python 2.5 might work as the type of os.stat(filename).st_mtime was changed from int to float and now offers subsecond resolution. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple inheritance of a dynamic list of classes?
On Feb 13, 9:14 am, Peter Otten [EMAIL PROTECTED] wrote: Avoid inheritance would be almost as justified :-) Yep, I strongly agree. Inheritance is overrated, as Guido says. For what concerns the debate of multiple vs single inheritance, yes it is true that multiple inheritance is worse, but even single inheritance can be bad enough, unfortunately :-( The issue is that inheritance *does not scale*: i.e. in simple situations it works fine, but it has the tendence to becomes unmanageable very easily In other words, if you are inheriting just two or three methods it may works, but when you start having dozens of methods inherited from different sources, your code will become to look as spaghetti code. This is why in general I (as many people here) suggest delegation over inheritance. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
re.search making no match == 0
Hey all, I have a search: VAR = re.search(PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? , pcpT9, re.S ).group(1) #.split()[1] that does not match (sometimes it will and sometimes it will not match) Traceback (most recent call last): File P:\Burke\TRACKERS\Ortho-McNeil\Automation\Wave3\test.py, line 53, in ? VAR = re.search(PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? , pcpT9, re.S ).group(1) #.split()[1] AttributeError: 'NoneType' object has no attribute 'group' Is there a way in python to make this non match equal a value (say, 0)? This one line is actually a series of searches Reasons = [EFFICACY,EFFECTIVE,WORKS QUICKLY,PROVEN,SAFETY,LITTLE,WELL, BETTER,SAMPLES] # Reasons(29) VAR = [re.search(r%s.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? % i, pcpT9, re.S ).group(1) for i in Reasons ] #.split()[1] and one of the items in the array may or may not be present. Lance -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple inheritance of a dynamic list of classes?
On 2007-02-15, Michele Simionato [EMAIL PROTECTED] wrote: On Feb 13, 9:14 am, Peter Otten [EMAIL PROTECTED] wrote: Avoid inheritance would be almost as justified :-) In other words, if you are inheriting just two or three methods it may works, but when you start having dozens of methods inherited from different sources, your code will become to look as spaghetti code. This is why in general I (as many people here) suggest delegation over inheritance. I consider inheritance in Python when I see that the class I'm implementing contains some sort of status code that controls behavior. For example: class Stream(object): def __init__(self, readable, writable): if readable and writable: self.io_type = 'inout' elif readable: self.io_type = 'out' else: self.io_type = 'in' That code sets me to thinking I'll get good mileage from: class Stream(object): ... class InStream(object): ... class OutStream(object): ... class InOutStream(object): ... I always get myself into trouble when I try to design a class hierarchy *before* I see something like that. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python interactive interpreter has no command history
Hello, How to configure Python2.5's interactive interpreter to get command history ? I always got ^[[A and ^[[B . Are you using Ubuntu? The last comes with 2.4.x and 2.5. This only occurs on 2.5. This happens when you compile Python with libreadline installed, AFAIK. FIll a bug in the Ubuntu launchpad. You can install libreadline (and build-essential), download the 2.5 source and compile yourself. -- EduardoOPadoan (eopadoan-altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python interactive interpreter has no command history
Hi, You need to have readline installed. Laurent ThomasC wrote: Hello, How to configure Python2.5's interactive interpreter to get command history ? I always got ^[[A and ^[[B . Thank you !! Thomas# -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin set literal
faulkner schrieb: On Feb 14, 11:55 am, Schüle Daniel [EMAIL PROTECTED] wrote: Hello, lst = list((1,2,3)) lst = [1,2,3] t = tupel((1,2,3)) t = (1,2,3) s = set((1,2,3)) s = ... it would be nice feature to have builtin literal for set type maybe in P3 .. what about? s = 1,2,3 Regards, Daniel sets aren't quite that useful or common. just use a list. and '' and '' already have syntactic meanings. well, I thought about this the empty set has the meaning of != now as far as I remember is depricated and will disappear When they are gone in P3000, could be reused as empty set. and that would make python look more like C++, which nobody wants. I dont think that actually many people fear this. we have {} for dicts and I doubt anybody mistake them for C++ brakets. In my previuos post I forgot to mention d = dict() d = {} s = set() s = why not, on the first sight everybody will see ... here our algorithmus deals with unique things/objects ... put in a set. Regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin set literal
Steven Bethard schrieb: Schüle Daniel wrote: Hello, lst = list((1,2,3)) lst = [1,2,3] t = tupel((1,2,3)) t = (1,2,3) s = set((1,2,3)) s = ... it would be nice feature to have builtin literal for set type maybe in P3 .. what about? s = 1,2,3 In Python 3.0, this looks like:: s = {1,2,3} jepp, that looks not bad .. as in a mathe book. the only disadvantage I see, that one may confuse it with a dict. Regards, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write a programe that include both pipe(low speed system call) and signal
On Feb 15, 2:51 am, Marco [EMAIL PROTECTED] wrote: Hi, I have know that signal will interrupt some kind low speed system call like pipe. But how to design a program that both support signal and pipe? I have a mplayer.py to play movie via os.popen2() and mplayer slave mode. And there is a mplayer_ctl.py send signal to mplayer.py to trigger function from mplayer.py. Sometimes os.popen2() is reading or writing when user run mplayer_ctl.py the bad things raise... Is there some better way to design the programe? Thank you -- LinuX Power Take a look at the subprocess module, which is meant to replace popen[1,2,3...](). Also, please try to explain the problem again, because I just can't decypher everything you're trying to do (and say). cheers, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: list of range of floats
On Thu, 15 Feb 2007 05:57:45 -0800, Bart Ogryczak wrote: On Feb 14, 6:12 pm, Steve [EMAIL PROTECTED] wrote: I'm trying to create a list range of floats and running into problems. I've tried it the easy way. Works. map(float,range(a,b)) Thanks Bart, I'll give it a try Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: re.search making no match == 0
Lance Hoffmeyer wrote: I have a search: VAR = re.search(PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? , pcpT9, re.S ).group(1) #.split()[1] that does not match (sometimes it will and sometimes it will not match) Traceback (most recent call last): File P:\Burke\TRACKERS\Ortho-McNeil\Automation\Wave3\test.py, line 53, in ? VAR = re.search(PROVEN.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? , pcpT9, re.S ).group(1) #.split()[1] AttributeError: 'NoneType' object has no attribute 'group' Is there a way in python to make this non match equal a value (say, 0)? match = re.search(...) if match: value = match.group(1) else: value = default Wrap that into a function and you can use it inside a list comprehension. This one line is actually a series of searches Reasons = [EFFICACY,EFFECTIVE,WORKS QUICKLY,PROVEN,SAFETY,LITTLE,WELL, BETTER,SAMPLES] # Reasons(29) VAR = [re.search(r%s.*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? % i, pcpT9, re.S ).group(1) for i in Reasons ] #.split()[1] and one of the items in the array may or may not be present. How about a slightly different approach (untested): r = re.compile(r(%s).*?\n[\sA-Za-z\(\)\/\-]+\d(.*?)\n.*? % |.join(reasons), re.S) groups = dict(m.groups() for m in r.finditer(pcpT9)) VAR = [groups.get(reason, 0) for reason in reasons] I recommend that you don't create the VAR list and use groups directly. If you are using Python 2.5 you can replace the builtin dict with a collections.defaultdict. Peter -- http://mail.python.org/mailman/listinfo/python-list
TKinter newbie
Hi Im new to gui programming from Tkinter import * # get widget classes from tkMessageBox import askokcancel # get canned std dialog class Quitter(Frame): # subclass our GUI def __init__(self, parent=None): # constructor method Frame.__init__(self, parent) self.pack() widget = Button(self, text='Quit', command=self.quit) widget.pack(side=LEFT) def quit(self): ans = askokcancel('Verify exit', Really quit?) if ans: Frame.quit(self) class Demo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text=Basic demos).pack() for (key, value) in demos.items(): func = (lambda key=key: self.printit(key)) Button(self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack()# here def printit(self, name): print name, 'returns =', demos[name]() My problem is in class Demo. How is the best way to use class Quitter in class Demo? should it be: Quitter(self).pack() Quitter(self) ... -- http://mail.python.org/mailman/listinfo/python-list
Which Object Database would you recommend for cross platform application?
Hello folks, I am currently developing an open source Event Managment software (events in real-life, like concerts, exhibitions etc. :-) ) using wx for the GUI, and I need an Object database. Since this is the first time I actually need doing this, I wondered if anybody here could recommend one. It can be fairly simple. It doesn't need threading support and will only host one client (the application, but I am thinking about making this database accessible via the web, but this is still far in the future), although the database might get big (around 1GiB). It should be available for linux, mac os and windows. I looked into ZODB, but thats totally overloaded for my purpose. I looked into Durus (a re-implementation of ZODB, but without this overloaded stuff, but the documentation is very thin). Both of them don't really appeal. So I wondered if any of you could recommend one that (more or less) best fits the described conditions. Thanks in advance, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Object Database would you recommend for cross platform application?
Thomas Ploch wrote: Hello folks, I am currently developing an open source Event Managment software (events in real-life, like concerts, exhibitions etc. :-) ) using wx for the GUI, and I need an Object database. Since this is the first time I actually need doing this, I wondered if anybody here could recommend one. It can be fairly simple. It doesn't need threading support and will only host one client (the application, but I am thinking about making this database accessible via the web, but this is still far in the future), although the database might get big (around 1GiB). It should be available for linux, mac os and windows. I looked into ZODB, but thats totally overloaded for my purpose. I looked into Durus (a re-implementation of ZODB, but without this overloaded stuff, but the documentation is very thin). Both of them don't really appeal. So I wondered if any of you could recommend one that (more or less) best fits the described conditions. Thanks in advance, Thomas This answer does not really answer your question. But have you looked a dabo (www.dabodev.com). It doesn't support the web (yet) but you said that's in the furture. Dabo was built for this type of app. Dabo supports Postgres,MsSQL,MySQL,Firebird, and SQLite. Non of the DB's are what I'd call an object database but is that a real requirement? BTW the first 4 DB's can support 1GB and more. Johnf -- http://mail.python.org/mailman/listinfo/python-list
Re: TKinter newbie
Gigs_ wrote: Hi Im new to gui programming from Tkinter import * # get widget classes from tkMessageBox import askokcancel # get canned std dialog class Quitter(Frame): # subclass our GUI def __init__(self, parent=None): # constructor method Frame.__init__(self, parent) self.pack() widget = Button(self, text='Quit', command=self.quit) widget.pack(side=LEFT) def quit(self): ans = askokcancel('Verify exit', Really quit?) if ans: Frame.quit(self) class Demo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text=Basic demos).pack() for (key, value) in demos.items(): func = (lambda key=key: self.printit(key)) Button(self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack()# here def printit(self, name): print name, 'returns =', demos[name]() My problem is in class Demo. How is the best way to use class Quitter in class Demo? should it be: Quitter(self).pack() Quitter(self) ... You are calling the Quitter's pack() method twice, once in Quitter.__init__() and then again in Demo.__init__(). I would remove the call in Quitter.__init__(). If you do that you can use your Quitter class with other layout managers which require other configuration methods, e. g. Quitter(...).grid(...). Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: TKinter newbie
Gigs_ wrote: Hi Im new to gui programming from Tkinter import * # get widget classes from tkMessageBox import askokcancel # get canned std dialog class Quitter(Frame): # subclass our GUI def __init__(self, parent=None): # constructor method Frame.__init__(self, parent) self.pack() widget = Button(self, text='Quit', command=self.quit) widget.pack(side=LEFT) def quit(self): ans = askokcancel('Verify exit', Really quit?) if ans: Frame.quit(self) class Demo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text=Basic demos).pack() for (key, value) in demos.items(): func = (lambda key=key: self.printit(key)) Button(self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack()# here def printit(self, name): print name, 'returns =', demos[name]() My problem is in class Demo. How is the best way to use class Quitter in class Demo? should it be: Quitter(self).pack() Quitter(self) ... The Quitter really needs to Destroy its parent, so you will need to have something like self.parent = parent in the __init__() method to keep a reference to the parent frame. Then the quit() method can call self.parent.destroy() which will also result in the destruction of the child Quitter. In this particular case you don't appear to need a reference to the Quitter object in the main Frame's code, so it's acceptable to use Quitter(self).pack() However in the more general case yo umight want to be abel to refer to some subsidiary object in the Frame's methods, and in that case the easiest way to do so is to save that reference when you create the object, than pack the obejct separately, as in self.quitter = Quitter(self) self.quitter.pack() Here's a simple program to show you the difference between quit() and destroy(). You will notice that you have to press the Quit button twice, but the Destroy button only once - once the window is destroyed calling its mainloop() method no longer does anything. from Tkinter import * t = Tk() Button(t, command=t.quit, text=Quit).pack() Button(t, command=t.destroy, text=Destroy).pack() t.mainloop() t.mainloop() regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive calls and stack
En Thu, 15 Feb 2007 13:37:19 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Feb 2007 10:41:53 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: So the effect is that mutual recursion isn't actually any harder. But some kind of language support is required in this case. At least I don't know how to handle mutual recursion (apart from inlining one function inside the other...). But I'm certainly not a program transformation guru (neither a novice!) so I would not be surprised if someone says it can be done... What happens (using the model of an imaginary virtual machine, perhaps like the Python interpreter) is the following. A normal function call pushes a call-frame onto a stack. The call-frame contains information necessary for returning from the function, and usually a place to store its local variables and parameters. A function called in tail position simply overwrites the current call-frame with the new one instead of pushing it onto the stack. This is the kind of language support menctioned. For tail recursion you don't require that support. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: SystemError: _PyImport_FixupExtension: module _types not loaded
On Feb 12, 2:25 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Mon, 12 Feb 2007 15:44:36 -0300, [EMAIL PROTECTED] escribió: I'm trying to write some C code that will run a python script that can in turn call some C functions. However I'm having a problem getting started because although I can run a script from the python ide that imports ctypes, when I execute that 'import ctypes' code from the C code I get the following error: 'import site' failed; use -v for traceback You have to fix this first. Probably you can't import anything, not just ctypes. Quoting myself from a similar problem: Try this: PyRun_SimpleString(import sys; print sys.path); to see where Python expects to find its library (or call the Py_GetPath function). You may need to call Py_SetProgramName (before Py_Initialize) so it can find where the standard library resides. At least for testing purposes, you can copy your executable into the same directory where Python is installed. -- Gabriel Genellina This is what I get: 'import site' failed; use -v for traceback ['c:\\temp\\pytest\\Debug\\python25_d.zip', 'C:\\Python25\\Lib', 'C:\ \Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', '', 'c:\\temp\\pytest\ \Debug'] In fact, the 'import site' failed; use -v for traceback happens when I call the Py_Initialize(). As can be seen from the output, the import sys; and print sys.path works. I also added Py_SetProgramName(argv[0]) before calling PyInitialize() but there was no change. Thanks, Steve -- http://mail.python.org/mailman/listinfo/python-list
RE engines and related matters
From Lambda the Ultimate blog, a link to an interesting article about such topics: http://swtch.com/~rsc/regexp/regexp1.html http://swtch.com/~rsc/regexp/ http://lambda-the-ultimate.org/node/2064 Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: rot13 in a more Pythonic style?
On 15 Feb, 17:55, Dennis Lee Bieber [EMAIL PROTECTED] wrote: Sounds more like a case for a parser/lexer wherein the emitted code tokens are the new style identifiers... 8-(I'm trying not to think about that Fortunately I don't think it's _quite_ that bad. -- http://mail.python.org/mailman/listinfo/python-list
Re: SystemError: _PyImport_FixupExtension: module _types not loaded
En Thu, 15 Feb 2007 15:42:51 -0300, [EMAIL PROTECTED] escribió: This is what I get: 'import site' failed; use -v for traceback ['c:\\temp\\pytest\\Debug\\python25_d.zip', 'C:\\Python25\\Lib', 'C:\ \Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', '', 'c:\\temp\\pytest\ \Debug'] In fact, the 'import site' failed; use -v for traceback happens when I call the Py_Initialize(). As can be seen from the output, the import sys; and print sys.path works. I also added Py_SetProgramName(argv[0]) before calling PyInitialize() but there was no change. works in the sense that it prints something; but sys.path is incomplete, it lacks site-packages and others (they are added by site.py). It appears that you have installed Python on C:\Python25 and you build your application executable into c:\temp\pytest\Debug - is that true? Hmmm, you will need a debug build of Python too, python25_d.lib/.dll. Perhaps at this stage it's easier to use the Release build, because you already have python25.lib/dll. You have to fix the import site error. Use the following command on a console window before launching your executable: set PYTHONVERBOSE=1 You'll see a lot of lines showing the initial imports; you should be able to detect what's the problem at import site; usually it's trying to load a missing DLL. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: reference data in a dictionary
Wensui Liu [EMAIL PROTECTED] wrote: I know dict['row1'] will always work. but it will only get 1 row out of the dict. is there anyway i can get multiple (1) rows out of dict by directly refeencing them, something like dict[['row1', 'row2']]. [d[x] for x in ('row1', 'row2')] -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
James Stroud [EMAIL PROTECTED] writes: I increasingly come to the decision to avoid tuples altogether because, eventually, you end up turning them into lists anyway I don't. I end up extracting them to separate variables. foo = (12, None, spam) # ... # much code, perhaps passing foo around as parameter # ... (bar, baz, wibble) = foo # code using bar, baz, and/or wibble If they are eventually extracted to lists, then it generally makes no sense for them ever to begin as a tuple. -- \ I have an answering machine in my car. It says, 'I'm home now. | `\ But leave a message and I'll call when I'm out.' -- Steven | _o__) Wright | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive calls and stack
On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 15 Feb 2007 13:37:19 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Feb 2007 10:41:53 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: So the effect is that mutual recursion isn't actually any harder. But some kind of language support is required in this case. At least I don't know how to handle mutual recursion (apart from inlining one function inside the other...). But I'm certainly not a program transformation guru (neither a novice!) so I would not be surprised if someone says it can be done... What happens (using the model of an imaginary virtual machine, perhaps like the Python interpreter) is the following. A normal function call pushes a call-frame onto a stack. The call-frame contains information necessary for returning from the function, and usually a place to store its local variables and parameters. A function called in tail position simply overwrites the current call-frame with the new one instead of pushing it onto the stack. This is the kind of language support menctioned. For tail recursion you don't require that support. I'm not sure what you mean. The above support is enough for tail recursion, mutual recursion, and any other tail call to be optimized. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Object Database would you recommend for cross platform application?
Thomas Ploch a écrit : Hello folks, I am currently developing an open source Event Managment software (events in real-life, like concerts, exhibitions etc. :-) ) using wx for the GUI, and I need an Object database. need ? Why ? (I don't mean you shouldn't use one, just questionning the need)... Since this is the first time I actually need doing this, I wondered if anybody here could recommend one. It can be fairly simple. It doesn't need threading support and will only host one client (the application, but I am thinking about making this database accessible via the web, but this is still far in the future), If you plan on making it accessible TTW, then you do need support for concurrent access. although the database might get big (around 1GiB). It should be available for linux, mac os and windows. I looked into ZODB, but thats totally overloaded for my purpose. I looked into Durus (a re-implementation of ZODB, but without this overloaded stuff, but the documentation is very thin). Both of them don't really appeal. The ZODB is quite easy to use, and it's probably the most used Python OODB actually. I have no experience with Durus, but it looked quite close when I last browsed the project page. Else you may want to look at Metakit, KirbyBase etc http://wiki.python.org/moin/DatabaseInterfaces So I wondered if any of you could recommend one that (more or less) best fits the described conditions. sqlite +SQLAlchemy. Yes, I know, that's not an object DB. -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive calls and stack
En Thu, 15 Feb 2007 16:35:25 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 15 Feb 2007 13:37:19 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: En Wed, 14 Feb 2007 10:41:53 -0300, Neil Cerutti [EMAIL PROTECTED] escribió: So the effect is that mutual recursion isn't actually any harder. But some kind of language support is required in this case. At least I don't know how to handle mutual recursion (apart from inlining one function inside the other...). But I'm certainly not a program transformation guru (neither a novice!) so I would not be surprised if someone says it can be done... What happens (using the model of an imaginary virtual machine, perhaps like the Python interpreter) is the following. A normal function call pushes a call-frame onto a stack. The call-frame contains information necessary for returning from the function, and usually a place to store its local variables and parameters. A function called in tail position simply overwrites the current call-frame with the new one instead of pushing it onto the stack. This is the kind of language support menctioned. For tail recursion you don't require that support. I'm not sure what you mean. The above support is enough for tail recursion, mutual recursion, and any other tail call to be optimized. I only want to say that tail *recursion* can be eliminated trivially transforming the code into a while loop, and that can be done by the programmer, and doesn't require compiler support. Head *recursion* can be eliminated too by using some storage as temporary stack, and that doesn't require external support either. Mutual recursion (and generic tail call elimination) require some sort of external support: one can't eliminate the call just by transforming the program. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Python code to do the *server* side of digest authentication?
Hi all, I've got a very simple HTML proxy server to access the web from my cell phone (based on this code: http://www.okisoft.co.jp/esc/python/proxy/). It's a very retarded phone that freezes if there's no Content-Length header and some other circumstances, so I have to tweak and modify the headers received slightly. But it works quite well with these hacks. Now I'd like to add proxy authentication so that I'm not running this open proxy all the time. I would like to use Digest authentication (http://en.wikipedia.org/wiki/Digest_access_authentication) rather than Basic authentication so as not to expose any plaintext password. It appears that there are plenty of Python libraries to do the *client* side of the authentication (e.g. urllib2) but I have not found much code that does the *server* side of the authentication. That is, I am looking for code to generate the WWW-Authentication header (including appropriate nonce and opaque string) and to verify the Authorization header sent by the client when it retries. It does not look *too* hard to implement, but it does involve crypto and I'd just as soon use some tried-and-true code rather than roll my own in this case. Does anyone have any suggestions of where to find such code? Thanks! Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code to do the *server* side of digest authentication?
Dan Lenski wrote: Hi all, I've got a very simple HTML proxy server to access the web from my cell phone (based on this code: http://www.okisoft.co.jp/esc/python/proxy/). It's a very retarded phone that freezes if there's no Content-Length header and some other circumstances, so I have to tweak and modify the headers received slightly. But it works quite well with these hacks. Now I'd like to add proxy authentication so that I'm not running this open proxy all the time. I would like to use Digest authentication (http://en.wikipedia.org/wiki/Digest_access_authentication) rather than Basic authentication so as not to expose any plaintext password. It appears that there are plenty of Python libraries to do the *client* side of the authentication (e.g. urllib2) but I have not found much code that does the *server* side of the authentication. That is, I am looking for code to generate the WWW-Authentication header (including appropriate nonce and opaque string) and to verify the Authorization header sent by the client when it retries. It does not look *too* hard to implement, but it does involve crypto and I'd just as soon use some tried-and-true code rather than roll my own in this case. Does anyone have any suggestions of where to find such code? Thanks! Dan I think that is because normally the web server does the authentication on the server side. Why not use Apache to do the digest authentication? http://httpd.apache.org/docs/2.0/mod/mod_auth_digest.html -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: SystemError: _PyImport_FixupExtension: module _types not loaded
works in the sense that it prints something; but sys.path is incomplete, it lacks site-packages and others (they are added by site.py). It appears that you have installed Python on C:\Python25 and you build your application executable into c:\temp\pytest\Debug - is that true? Hmmm, you will need a debug build of Python too, python25_d.lib/.dll. Perhaps at this stage it's easier to use the Release build, because you already have python25.lib/dll. You have to fix the import site error. Use the following command on a console window before launching your executable: set PYTHONVERBOSE=1 You'll see a lot of lines showing the initial imports; you should be able to detect what's the problem at import site; usually it's trying to load a missing DLL. -- Gabriel Genellina Thank you for your quick reply and your interest. I had a debug python25_d.lib/dll which i was even using to step into the code to see why it was failing but it will take me more time to understand the python code. The other interesting thing I discovered when trying to build my debug python dll with vs2005 usig the build8 solution was that I was even getting the exact same error: Traceback (most recent call last): File string, line 1, in module File C:\Python25\lib\ctypes\__init__.py, line 6, in module import os as _os, sys as _sys File C:\Python25\lib\os.py, line 690, in module import copy_reg as _copy_reg File C:\Python25\lib\copy_reg.py, line 7, in module from types import ClassType as _ClassType File C:\Python25\lib\types.py, line 93, in module import _types SystemError: _PyImport_FixupExtension: module _types not loaded that I was getting when when trying to run the script. I decided at that point to go back to python2.4, actually activestate python2.4 and then add the ctype module. I will update this thread on my success or failure. Thanks, Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive calls and stack
On 2007-02-15, Gabriel Genellina [EMAIL PROTECTED] wrote: I'm not sure what you mean. The above support is enough for tail recursion, mutual recursion, and any other tail call to be optimized. I only want to say that tail *recursion* can be eliminated trivially transforming the code into a while loop, and that can be done by the programmer, and doesn't require compiler support. Head *recursion* can be eliminated too by using some storage as temporary stack, and that doesn't require external support either. Mutual recursion (and generic tail call elimination) require some sort of external support: one can't eliminate the call just by transforming the program. Ah, I see now. Had my blinders on. -- Neil Cerutti Low Self-Esteem Support Group will meet Thursday at 7 to 8:30 p.m. Please use the back door. --Church Bulletin Blooper -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
Sergey posix.stat_result is CLASS, not regular tuple. I believe it morphed from being a tuple though. I wasn't suggesting that Sergey It it morphed, the tuple nature of it is just history now. No, it is still full of tuple-fu: import os s = os.stat(/etc/hosts) s (33188, 92111L, 26738688L, 1, 0, 1, 355L, 1171570459, 1164401316, 1171087243) type(s) type 'posix.stat_result' s.st_mtime 1164401316 s[0:3] (33188, 92111L, 26738688L) s[4:] + s[0:3] (0, 1, 355L, 1171570459, 1164401316, 1171087243, 33188, 92111L, 26738688L) type(s[4:] + s[0:3]) type 'tuple' The notion of tuples as records in Python is not new: http://mail.python.org/pipermail/python-list/1999-December/thread.html Search for super tuples. Sergey Did it go beyond just talking? Raymond Hettinger just proposed adding a pure Python implementation to Python 2.6. The version he's been using for about a year is here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/500261 Sergey We can think about tuples anything, but are they something other Sergey than freezed lists? We can index them, slice, iterate, Sergey map/redice/filter, can cast (fuckin C!) to lists and back - Sergey what the difference?? Tuples is similar to records - I think Sergey this is just topological artefact, generated when python was Sergey compared with some other languague :) The fact that tuples and lists share so many implementation details makes people think of tuples as immutable lists. That view has its uses (allowing you to pretend that you can use lists as dictionary keys or take advantage of the compile-time allocation of tuples of constants, for example), but I don't think that makes the view of tuples as records a topological artifact. I'm not sure where you believe Python was compared to some other language. My original comment was that tuples could be thought of more like C structs or Pascal records. That was an analogy, not a language comparison. Sergey classes have sintactically and functionally overcame Sergey records/structs - why to drag to the same role tuples, that have Sergey not initially any feature of record? They have a number of record-like features. They are relatively compact (unlike class instances), once instantiated they can't be extended (unlike lists or class instances in the common case). They just don't yet have named attributes. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code to do the *server* side of digest authentication?
On Feb 15, 3:19 pm, Larry Bates [EMAIL PROTECTED] wrote: I think that is because normally the web server does the authentication on the server side. Why not use Apache to do the digest authentication? http://httpd.apache.org/docs/2.0/mod/mod_auth_digest.html -Larry Hi Larry, I'm sorry that I wasn't clear in my original post! I don't need to do the server authentication on the proxy (WWW-Authentication and Authorization). What I need to do is the *proxy* authentication (Proxy-Authentication and Proxy-Authorization). Those headers are identical to the first pair, but they are handled by the proxy; if the client isn't authorized, then they can't use the proxy. Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin set literal
Schüle Daniel wrote: Steven Bethard schrieb: Schüle Daniel wrote: it would be nice feature to have builtin literal for set type maybe in P3 .. what about? s = 1,2,3 In Python 3.0, this looks like:: s = {1,2,3} jepp, that looks not bad .. as in a mathe book. the only disadvantage I see, that one may confuse it with a dict. Perhaps with a very cursory inspection. But the lack of any ':' characters is a pretty quick clue-in. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Pep 3105: the end of print?
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of this pep would be to make it impossible to use the name 'print' in a backward compatible manner. Indeed, if a program is to compile in both Python 2.x and Python 3.x, the print function (or the print statement with parentheses) can not use the 'sep', 'end' and 'file' keywords. This in turn makes it impossible to support the effect of print with trailing comma in Python 2.x programs while retaining the name 'print'. The only workaround would be to define yet another function, with a name *other* than 'print'. This function, say print2, can support whatever features the implementer wants because it does not collide with the Python 2.x print statement. In short, pep 3105 will *discourage* rather than encourage the use of the name 'print'. Rather than invalidating most Python 2.x programs, it would seem more graceful for Python 3.x to define a [your name here] function that can be used in addition to, rather than to the exclusion of, print. Edward P.S. The existence of an automated translation script does not change the situation described above in any way. At best, such a script could change print statements to [your name here] functions, but the effect would still be the elimination of the name 'print' in all programs that aim to support Python 2.x and Python 3.x. EKR Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: f---ing typechecking
[EMAIL PROTECTED] writes: My original comment was that tuples could be thought of more like C structs or Pascal records. Should f(*args) receive a list rather than a tuple arg? -- http://mail.python.org/mailman/listinfo/python-list
Automated resizing of JPEG image + making slices?
Hello everybody. I'm currently involved in a site building project in which we're going to use the Google Maps API. The user will be able to browse the site by looking over a really large image, similar to how Google Maps itself works, except with the design of the site on the background rather than a map of the world. I initially hired someone to do it in PHP (don't bite, please :-) but it seems that I forgot about one thing: the people updating the site would have been able to upload a huge 30 MB JPEG image, which PHP would then resize to various sizes and cut them into 200x200 pieces, which would be fed to the Google Maps API. However, this costs a lot of memory, and PHP by default only has 8 MB. The programmer offered to do a C++ image manipulator, but he uses Windows and the people who update the site use Mac OS X. It would be tedious. Then I thought that Python might solve me the head-ache. I know some Python (but not much since I've never actually written that many things in it), and with some effort I could probably make a simple image manipulator frontend in it, but only if I can find a good library for doing the actual manipulation. Do any of you know such libraries? Many thanks, Michiel Sikma [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
ANNOUNCE: Mod_python 3.3.1
The Apache Software Foundation and The Apache HTTP Server Project are pleased to announce the 3.3.1 release of mod_python. Mod_python 3.3.1 is considered a stable release, suitable for production use. Mod_python is an Apache HTTP Server module that embeds the Python language interpreter within the server. With mod_python you can write web-based applications in Python that will run many times faster than traditional CGI and will have access to advanced features such as ability to maintain objects between requests, access to httpd internals, content filters and connection handlers. The 3.3.1 release has many new features, feature enhancements, fixed bugs and other improvements over the previous version. See Appendix A of mod_python documentation for more details. Mod_python 3.3.1 is released under the new Apache License version 2.0. Mod_python 3.3.1 is available for download from: http://httpd.apache.org/modules/python-download.cgi More infromation about mod_python is available at: http://httpd.apache.org/modules/ Many thanks to everyone who contributed to and helped test this release, without your help it would not be possible! Regards, The Apache Mod_python team. -- http://mail.python.org/mailman/listinfo/python-list
Re: filecmp.cmp() cache
On Feb 15, 5:56 pm, Peter Otten [EMAIL PROTECTED] wrote: You can clear the cache with filecmp._cache = {} as a glance into the filecmp module would have shown. You are right, a quick glance would have enlighten me. Next time I will RTFS first. :-) If you don't want to use the cache at all (untested): class NoCache: def __setitem__(self, key, value): pass def get(self, key): return None filecmp._cache = NoCache() Just one small tought/question. How likely am I to run into trouble because of this? I mean, by setting _cache to another value I'm mucking about in filecmp's implementation details. Is this generally considered OK when dealing with Python's standard library? :.:: mattias -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated resizing of JPEG image + making slices?
Michiel Sikma wrote: Hello everybody. I'm currently involved in a site building project in which we're going to use the Google Maps API. The user will be able to browse the site by looking over a really large image, similar to how Google Maps itself works, except with the design of the site on the background rather than a map of the world. I initially hired someone to do it in PHP (don't bite, please :-) but it seems that I forgot about one thing: the people updating the site would have been able to upload a huge 30 MB JPEG image, which PHP would then resize to various sizes and cut them into 200x200 pieces, which would be fed to the Google Maps API. However, this costs a lot of memory, and PHP by default only has 8 MB. The programmer offered to do a C++ image manipulator, but he uses Windows and the people who update the site use Mac OS X. It would be tedious. Then I thought that Python might solve me the head-ache. I know some Python (but not much since I've never actually written that many things in it), and with some effort I could probably make a simple image manipulator frontend in it, but only if I can find a good library for doing the actual manipulation. Do any of you know such libraries? PIL, the Python Imaging Library, would seem to be the ideal candidate. See http://www.pythonware.com/products/pil/ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Pep 3105: the end of print?
Edward K Ream wrote: The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of this pep would be to make it impossible to use the name 'print' in a backward compatible manner. You could offer up a patch for Python 2.6 so that you can do:: from __future__ import print_function and have the 'print' statement replaced by the 'print' function. That said, why can't you use ``file.write()`` instead of ``print``? While I use print quite frequently in interactive use, it's pretty much nonexistent in all my real code. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated resizing of JPEG image + making slices?
Michiel Sikma [EMAIL PROTECTED] writes: I know some Python (but not much since I've never actually written that many things in it), and with some effort I could probably make a simple image manipulator frontend in it, but only if I can find a good library for doing the actual manipulation. Do any of you know such libraries? Search for Python Imaging Library. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pep 3105: the end of print?
You could offer up a patch for Python 2.6 so that you can do:: from __future__ import print_function This would only work for Python 2.6. Developers might want to support Python 2.3 through 2.5 for awhile longer :-) why can't you use ``file.write()`` instead of ``print``? Precisely my point: pep 3105 will force the elimination of the name 'print'. Edward Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: output to console and to multiple files
On Feb 15, 8:51 am, Matimus [EMAIL PROTECTED] wrote: On Feb 15, 7:53 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Feb 14, 5:10 pm, goodwolf [EMAIL PROTECTED] wrote: like this? class Writers (object): def __init__(self, *writers): self.writers = writers def write(self, string): for w in self.writers: w.write(string) def flush(self): for w in self.writers: w.flush(): import sys logfile = open('log.txt', 'w') sys.stdout = Writers(aya.stdout, file('log.out', 'w'), logfile) sys.stderr = Writers(aya.stdout, file('log.err', 'w'), logfile) i've tried simliar methods to this and to what Matimus wrote. I know it works great when using print statements. However, I'm looking to find something that will work with the output from a subprocess, such as from spawn, os.system, os.popen, etc. I think you should be able to use my or goodwolf's solution with the subprocess module. Something like this (untested): [code] class TeeFile(object): def __init__(self,*files): self.files = files def write(self,txt): for fp in self.files: fp.write(txt) if __name__ == __main__: import sys from subprocess import Popen command = whatever you want to run outf = file(log.out,w) errf = file(log.err,w) allf = file(log.txt,w) Popen( command, stdout = TeeFile(sys.__stdout__,outf,allf), stderr = TeeFile(sys.__stderr__,errf,allf) ) [/code] I tried this at lunch and it doesn't work. Some version of this method may work, but Popen tries to call the 'fileno' method of the TeeFile object (at least it did on my setup) and it isn't there. This is just a preemptive warning before someone comes back to let me know my code doesn't work. -- http://mail.python.org/mailman/listinfo/python-list
Re: filecmp.cmp() cache
Mattias Brändström wrote: On Feb 15, 5:56 pm, Peter Otten [EMAIL PROTECTED] wrote: You can clear the cache with filecmp._cache = {} as a glance into the filecmp module would have shown. You are right, a quick glance would have enlighten me. Next time I will RTFS first. :-) If you don't want to use the cache at all (untested): class NoCache: def __setitem__(self, key, value): pass def get(self, key): return None filecmp._cache = NoCache() Just one small tought/question. How likely am I to run into trouble because of this? I mean, by setting _cache to another value I'm mucking about in filecmp's implementation details. Is this generally considered OK when dealing with Python's standard library? I think it's a feature that Python lends itself to monkey-patching, but still there are a few things to consider: - Every hack increases the likelihood that your app will break in the next version of Python. - You take some responsibility for the patched code. It's no longer the tried and tested module as provided by the core developers. - The module may be used elsewhere in the standard library or third-party packages, and failures (or in the above example: performance degradation) may ensue. For a script and a relatively obscure module like 'filecmp' monkey-patching is probably OK, but for a larger app or a module like 'os' that is heavily used throughout the standard lib I would play it safe and reimplement. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Automated resizing of JPEG image + making slices?
Michiel Sikma wrote this on Thu, 15 Feb 2007 22:21:34 +0100. My reply is below. -snip- I initially hired someone to do it in PHP (don't bite, please :-) but it seems that I forgot about one thing: the people updating the site would have been able to upload a huge 30 MB JPEG image, which PHP would then resize to various sizes and cut them into 200x200 pieces, which would be fed to the Google Maps API. However, this costs a lot of memory, and PHP by default only has 8 MB. -snip- I know some Python (but not much since I've never actually written that many things in it), and with some effort I could probably make a simple image manipulator frontend in it, but only if I can find a good library for doing the actual manipulation. Do any of you know such libraries? I can't make head or tail of your project's constraints, so the following advice probably isn't worth much. IMHO, slicing and dicing is best done by stand-alone, special-purpose, image-manipulation routines that do their own I/O. Here is a library of such routines: o http://netpbm.sourceforge.net/doc/directory.html These can be chained together (piped) in shell script (or in *python* if you prefer) if they're installed on your server. There is an API (and maybe even a *python* interface), but I've never needed it. For security, the parameters passed to these routines from the wild (such as file names) need to be scrubbed clean of any delimiters that would look like executable shell script code, variable substitutions, or even spurious path names. -- .. Chuck Rhode, Sheboygan, WI, USA .. Weather: http://LacusVeris.com/WX .. 18° — Wind WNW 13 mph -- http://mail.python.org/mailman/listinfo/python-list