The 3rd Python Game Programming Challenge is Over!
PyWeek #3 has now finished with the judging results coming in and declaring the winners to be: Individual - Bouncy the Hungry Rabbit http://www.pyweek.org/e/bouncy/ Team - Typus Pocus http://www.pyweek.org/e/PyAr2/ Congratulations to everyone who entered! The full list of entries is available at http://www.pyweek.org/3/entries/ The next PyWeek will be in March, 2007. Richard -- Visit the PyWeek website: http://www.pyweek.org/ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Building things with setup.py
James Stroud schrieb: I think I would like to know how to avoid or correct these sort of issues in the future, which seem to be limited, for me at least, to scipy and numpy, with the possible exception of MySQLdb and its dependency on zlib. Ideally, I would like to understand exactly what causes these errors in addition to knowing what I can do to correct them in the future. Let's take a specific failure, namely the line /auto_nfs/data10/users/jstroud/Programs/bin/g77 -L/data10/users/jstroud/Programs/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 build/temp.linux-i686-2.5/numpy/core/blasdot/_dotblas.o -L/data10/users/jstroud/Programs/lib -lblas -lg2c -o build/lib.linux-i686-2.5/numpy/core/_dotblas.so This gives errors like build/temp.linux-i686-2.5/numpy/core/blasdot/_dotblas.o(.text+0x758):numpy/core/blasdot/_dotblas.c:226: undefined reference to `PyTuple_New' That's not too surprising: this line tries to link the input *as an executable program*, despite calling the output _dotblas.so. In an executable program, all symbols need to be defined; that's why it it complains about so many missing symbols (including MAIN__ - which should never be missing in a library). Even though adding python2.5.a to the linker link makes these symbols appear, the result still won't work, as you can't use an executable program file as if it were a shared library. Now, compare this to a succeeding build of a C extension module, gcc -pthread -shared -L/data10/users/jstroud/Programs/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 -I/data10/users/jstroud/Programs/include -I/data10/users/jstroud/Programs/qt/include -I/usr/include -I/data10/users/jstroud/Programs/include/freetype2/freetype build/temp.linux-i686-2.5/build/src.linux-i686-2.5/numpy/core/src/umathmodule.o -lm -o build/lib.linux-i686-2.5/numpy/core/umath.so Notice that this passes -shared to the compiler, requesting construction of a shared library. This is the problem with the g77 linker line; try invoking /auto_nfs/data10/users/jstroud/Programs/bin/g77 -shared -L/data10/users/jstroud/Programs/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 build/temp.linux-i686-2.5/numpy/core/blasdot/_dotblas.o -L/data10/users/jstroud/Programs/lib -lblas -lg2c -o build/lib.linux-i686-2.5/numpy/core/_dotblas.so manually (whether or not -pthread is also necessary or supported for g77, I don't know). This should at least make the complaints about missing symbols go away; you should then see whether the resulting module can be imported in Python. If that solves the problem, the question is why the -shared option isn't passed automatically; your setting LDFLAGS might indeed be a cause. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils on Windows with VC++ 8
Rob Williscroft schrieb: Having read Noel Byron's reply also, I'm tempted to say there is some confusion here between a Visual *Studio* toolkit (VS 2003) and a Visual *C++* toolkit (VC 2003). Ah, that could well be. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)
metaperl wrote: Hello, I am looking for a module which has * log levels * output to stdout and file (either/or based on config) * nicely formatted log output (e.g., indentation when appropriate) I tried to use cheeseshop to find such a module, but came up short. I clicked on Browse Tree - Software Development but then did not see a subcategory for logging, so did not know where to look. I then typed log into the search box, but that didn't really turn up the modules which had login their description so I posted here. You should look in the standard library before hitting the Package Index. http://www.python.org/doc/current/lib/module-logging.html -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.5 Installation and Tkinter
milan_sanremo schrieb: cc -shared build/temp.solaris-2.10-i86pc-2.5/tmp/Python-2.5/Modules/_tkinter.o build/temp.solaris-2.10-i86pc-2.5/tmp/Python-2.5/Modules/tkappinit.o -L/usr/openwin/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11 -o build/lib.solaris-2.10-i86pc-2.5/_tkinter.so Yet, the file exists in /usr/local/lib. What am I missing? The system doesn't look in /usr/local/lib when searching for shared libraries. You have the usual options: 1. Set LD_RUN_PATH at build time to include /usr/local/lib 2. Set LD_LIBRARY_PATH at run time to include /usr/local/lib 3. Use crle to add /usr/local/lib to the system wide search path Even though it is quite intrusive, I typically prefer to do 3. That way, I don't have to hard-code library paths into executables, don't need my users to set environment variables, and have most autoconf-based software work out of the box. If you have never used crle before, understand that great care is necessary in using it. See the EXAMPLES in crle(8). You can either use -u -l to add a directory at the end of the search path, or just -l to overwrite the search path; make sure the original search path is still included. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Doctests for nested functions
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Can doctests be added to nested functions too? (This can be useful to me, I use nested function when I don't have attributes that I have to remember, but I want to split the logic in some subparts anyway). I think we had that discussion before, but that's not what nested functions are for (in Python). Use modules for that. Also solves your doctest problem nicely. Just -- http://mail.python.org/mailman/listinfo/python-list
how to remember login in zope?
how to remember login in zope? so when user came back , they needn't input username and password again. i'm using zope,extensiveuserfolder and cookiecrumbler, exuserfolder is set to cookie-based authentication. i'm not using cmf or plone , how could i handle this? thanks a lot. i'm working around this for two days and surfing a lot of pages but still felt confused, any suggestion would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Doctests for nested functions
Just wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: Can doctests be added to nested functions too? (This can be useful to me, I use nested function when I don't have attributes that I have to remember, but I want to split the logic in some subparts anyway). I think we had that discussion before, but that's not what nested functions are for (in Python). Use modules for that. Also solves your doctest problem nicely. Just Just is right. But... I struggled with coming up with something. The problem is that bar does not exist in the right form unlee you are executing the function so: def foo(_test = False): r foo() 21 foo(_test = True) 20 def bar(): bar() 11 print 10 print 20 if _test: _locals = locals() import doctest g = globals().copy() g.update(_locals) g['__test__'] = {} _totest = {} for loc in _locals.values(): try: if loc.__doc__ and loc.__name__ and (loc.__name__ not in g['__test__']): _totest[loc.__name__] = loc except: pass for _name, _testing in sorted(_totest.items()): doctest.run_docstring_examples(_testing, g, name = foo: + _name) import doctest doctest.testmod() The output is: Trying: foo() Expecting: 21 ** File __main__, line 3, in __main__.foo Failed example: foo() Expected: 21 Got: 20 Trying: foo(_test = True) Expecting: 20 ** File __main__, line 5, in __main__.foo Failed example: foo(_test = True) Expected: 20 Got: 20 ** File __main__, line 10, in foo:bar Failed example: bar() Expected: 11 Got: 10 1 items had no tests: __main__ ** 1 items had failures: 2 of 2 in __main__.foo 2 tests in 2 items. 0 passed and 2 failed. ***Test Failed*** 2 failures. *** DocTestRunner.merge: '__main__.foo' in both testers; summing outcomes. *** DocTestRunner.merge: '__main__' in both testers; summing outcomes. - Paddy. (but use a module instead)! -- http://mail.python.org/mailman/listinfo/python-list
Re: what is the best practice to separate Pygtk and long running thread code
Hi, I am running on WinXP so that is not so convenient to communicate between separate processes. In the past I have used blocking files but it may be a slow communication way for some applications. It may also be too much depending on the disk on which the program is run (network drives with different rights). It seems that RPC call would do the job but I would have liked something simplier (although I did not tried it). The best thing would be to have a queue feature that would be be shared between processes but as far as I know It does not exists in python. Thanks. Seb Do you know of some features like a queue that [EMAIL PROTECTED] wrote: seb wrote: Hi, I am using pygtk for the first times. I am wondering what would be the best pattern to interface pygtk with a thread. The thread is collecting informations (over the network for example) or is doing some long calculations. It sounds like you don't need to share all your memory--any time you're trying to seperate threads, you probably want to be using processes instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: Building things with setup.py
Ben Finney wrote: James Stroud [EMAIL PROTECTED] writes: rantI try things until a build works. I consider everything I do until acquiring a working build as necessary. Going back to see exactly what I did to make things work is not a viable option Before trying such I don't know what I need to do, but I'm going to want to know after I do it procedures, I usually start 'script' in the shell session and then start all my experimenting. ('script' is a tool from BSD available on most GNU/Linux distributions as well.) That way, the entire session, fumbling dead-ends and all, is available for later examination and trimming back to a what I did to get it working document. Beautiful suggestion. I've never even heard of that before. With OS X Terminal.app, I can buffer unlimited lines on my 6 year old ibook I use at home and on the road. But at work, on my brand new dual pentium, I've found myself limited to the thousand or so lines that konsole gives me. James -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
Steve Holden wrote: Is this a serious suggestion, or simply an attempt at sardonic obscurantism? Well, I was being serious, but now I'm afraid to see what kind of evils I've acidentally stepped in, heh!? I honestly don't see anything wrong with creating a DSL for a given problem domain. Where did I go astray? Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Blogging solution on SkunkWeb
Hi, I use SkunkWeb as my application server for my web application. I intend to put up a blog on the website but I haven't been able to find out a good blogging software for SkunkWeb. Most of them are based on Zope/Plone or use CGI or mod_python. The basic features I need are: 1. Multi-user blogs 2. Post Archives 3. RSS/Atom Syndication 4. Categorization of posts Please suggest a good blogging solution based on SkunkWeb which can satisfy my requirements. Regards, Shalin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)
metaperl wrote: Hello, I am looking for a module which has * log levels * output to stdout and file (either/or based on config) * nicely formatted log output (e.g., indentation when appropriate) Sorry for being nosey, but how'd you use indentation in a log? Regards, Björn -- BOFH excuse #154: You can tune a file system, but you can't tune a fish (from most tunefs man pages) -- http://mail.python.org/mailman/listinfo/python-list
Re: grabbing random words
Jay wrote: How would I be able to grab random words from an internet source. I'd like to grab a random word from a comprehensive internet dictionary. What would be the best source and the best way to go about this? The *best* source would be a function of the internet dictionary that selects a random word and passes it to you. Otherwise you'd have to read quite an amount of words, and select one yourself. (Sorry if this sounds/is super noobish.) It's quite difficult to let readable and complete questions (also with meaningful subject) sound noobish ;) Regards, Björn -- BOFH excuse #265: The mouse escaped. -- http://mail.python.org/mailman/listinfo/python-list
Re: Building things with setup.py
Martin v. Löwis wrote: James Stroud schrieb: I think I would like to know how to avoid or correct these sort of issues in the future, which seem to be limited, for me at least, to scipy and numpy, with the possible exception of MySQLdb and its dependency on zlib. Ideally, I would like to understand exactly what causes these errors in addition to knowing what I can do to correct them in the future. Let's take a specific failure, namely the line /auto_nfs/data10/users/jstroud/Programs/bin/g77 -L/data10/users/jstroud/Programs/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 build/temp.linux-i686-2.5/numpy/core/blasdot/_dotblas.o -L/data10/users/jstroud/Programs/lib -lblas -lg2c -o build/lib.linux-i686-2.5/numpy/core/_dotblas.so This gives errors like build/temp.linux-i686-2.5/numpy/core/blasdot/_dotblas.o(.text+0x758):numpy/core/blasdot/_dotblas.c:226: undefined reference to `PyTuple_New' That's not too surprising: this line tries to link the input *as an executable program*, despite calling the output _dotblas.so. In an executable program, all symbols need to be defined; that's why it it complains about so many missing symbols (including MAIN__ - which should never be missing in a library). Even though adding python2.5.a to the linker link makes these symbols appear, the result still won't work, as you can't use an executable program file as if it were a shared library. Now, compare this to a succeeding build of a C extension module, gcc -pthread -shared -L/data10/users/jstroud/Programs/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 -I/data10/users/jstroud/Programs/include -I/data10/users/jstroud/Programs/qt/include -I/usr/include -I/data10/users/jstroud/Programs/include/freetype2/freetype build/temp.linux-i686-2.5/build/src.linux-i686-2.5/numpy/core/src/umathmodule.o -lm -o build/lib.linux-i686-2.5/numpy/core/umath.so Notice that this passes -shared to the compiler, requesting construction of a shared library. This is the problem with the g77 linker line; try invoking /auto_nfs/data10/users/jstroud/Programs/bin/g77 -shared -L/data10/users/jstroud/Programs/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.3 build/temp.linux-i686-2.5/numpy/core/blasdot/_dotblas.o -L/data10/users/jstroud/Programs/lib -lblas -lg2c -o build/lib.linux-i686-2.5/numpy/core/_dotblas.so manually (whether or not -pthread is also necessary or supported for g77, I don't know). This should at least make the complaints about missing symbols go away; you should then see whether the resulting module can be imported in Python. If that solves the problem, the question is why the -shared option isn't passed automatically; your setting LDFLAGS might indeed be a cause. Regards, Martin As per your and Robert Kern's suggestions, unsetenv'ing $LDFLAGS and $CPPFLAGS indeed did the trick for numpy, scipy, and mysqldb. What a tough lesson in distutils! COMMENTARYThough great for self development, I'm not so sure such lessons should be necessary to build these tools./COMMENTARY James James -- http://mail.python.org/mailman/listinfo/python-list
Re: no-installation version of python
Robert Kern wrote: I think he wants a no-install (or, perhaps more accurately, simply-unzip-to-install) version of the interpreter that doesn't need to touch the Windows registry or copy DLLs to system locations. py2exe builds such a thing (or nearly so) for the application itself, if it works. Ah, I understand. Thx. Regards, Björn -- BOFH excuse #446: Mailer-daemon is busy burning your message in hell. -- http://mail.python.org/mailman/listinfo/python-list
Re: Building things with setup.py
Robert Kern wrote: Okay, this is possibly part of the problem. numpy.distutils handles FORTRAN code differently than other extension modules; this is why pure C extension modules both inside numpy and elsewehere were linking fine. Try unsetenving $CPPFLAGS and $LDFLAGS and adding those arguments to build_ext, if necessary. Looking on line 516 of numpy/fcompiler/__init__.py (why there's a class definition in __init__.py, I'll never know), it does look like the linker flags which are carefully constructed by numpy.distutils are indeed overridden by the user's setting of $LDFLAGS. I unset $LDFLAGS and $CPPFLAGS (not trying one at a time), and this did the trick. Everything built without a hitch. James -- http://mail.python.org/mailman/listinfo/python-list
Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)
At Saturday 23/9/2006 06:35, Bjoern Schliessmann wrote: Hello, I am looking for a module which has * log levels * output to stdout and file (either/or based on config) * nicely formatted log output (e.g., indentation when appropriate) Sorry for being nosey, but how'd you use indentation in a log? I do - what's wrong? Imagine the following on a single line... [328] 2006-09-23T06:41:50 BLATHER(-100) VerboseSecurity Unauthorized: Your [328] user account does not have the required permission. Access to [328] 'manage_main' of (Folder instance at 033C8290) (/Softlab/otros) [328] denied. Your user account, softlab, exists at /acl_users. Access [328] requires one of the following roles: ['Softlab']. Your roles in this [328] context are ['Authenticated', 'Manager', 'Owner']. Gabriel Genellina Softlab SRL __ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatic import PEP
Opinions? Great :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)
Gabriel Genellina wrote: [log w/indentation] I do - what's wrong? Imagine the following on a single line... Ah, K. Got it :) Regards, Björn -- BOFH excuse #351: PEBKAC (Problem Exists Between Keyboard And Chair) -- http://mail.python.org/mailman/listinfo/python-list
Re: grabbing random words
Jay: How would I be able to grab random words from an internet source. I'd like to grab a random word from a comprehensive internet dictionary. What would be the best source and the best way to go about this? Why do you need to grab them from the net? A simpler solution seems to keep a local file containing the sequence of words. You can find some open source sequences of such words. Then you can read all the words in a list, and use random.choice to take one of them randomly. If you don't want to keep all the dictionary/lexer (that can be up to 20 MB if it's a lexer) in memory you can (knowing the len of the file) seek a random position, and read 20-30 bytes, and take the word inside it (or you can create a dictionary file where each word is contained in in a fixed len of chars, so you can seek exactly a single word). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Python and checked exceptions
A new cookbook recipe suggesting two decorators @throws and @catches for treatment of checked exceptions in Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498131 This might be of practical interest for some and theoretical interest for others - in particular those who know checked ex as a language feature of Java. Regards, Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)
Robert Kern wrote: metaperl wrote: Hello, I am looking for a module which has You should look in the standard library before hitting the Package Index. http://www.python.org/doc/current/lib/module-logging.html Very nice module. Thanks for the pointer. -- http://mail.python.org/mailman/listinfo/python-list
re vs sre?
I learned about Python regular expressions from the Web documentation http://docs.python.org/lib/lib.html. This describes a module named re. Then I saw some code written by a colleague, and he was using a module named sre. I checked my Python 2.4.3 installation, and sure enough, I have a module named sre as well as re. Curious, I fired up an interactive Python session, and looked to see what the docstrings were for these modules. And for the re module, the help says: re - Minimal re compatibility wrapper. See sre for documentation. and sre seems to have the more complete set of docstrings. So which one should we be using? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and checked exceptions
Kay Schluehr wrote: A new cookbook recipe suggesting two decorators @throws and @catches for treatment of checked exceptions in Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498131 This might be of practical interest for some and theoretical interest for others - in particular those who know checked ex as a language feature of Java. Probably not what you wanted: test() Raises UncheckedExceptionError(exceptions.ZeroDivisionError) - OK Raises ZeroDivisionError - OK Traceback (most recent call last): File stdin, line 1, in ? File checked_exceptions.py, line 134, in test test4(3,2) UnboundLocalError: local variable 'test4' referenced before assignment Peter -- http://mail.python.org/mailman/listinfo/python-list
A critique of cgi.escape
The escape function in the cgi module escapes characters with special meanings in HTML. The ones that need escaping are '', '' and ''. However, cgi.escape only escapes the quote character if you pass a second argument of True (the default is False): cgi.escape(the \quick\ brown fox) 'the quick amp; lt;browngt; fox' cgi.escape(the \quick\ brown fox, True) 'the quot;quickquot; amp; lt;browngt; fox' This seems to me to be dumb. The default option should be the safe one: that is, escape _all_ the potentially troublesome characters. The only time you can get away with NOT escaping the quote character is outside of markup, e.g. TEXTAREA unescaped quotes allowed here /TEXTAREA Nevertheless, even in that situation, escaped quotes are acceptable. So I think the default for the second argument to cgi.escape should be changed to True. Or alternatively, the second argument should be removed altogether, and quotes should always be escaped. Can changing the default break existing scripts? I don't see how. It might even fix a few lurking bugs out there. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and checked exceptions
In message [EMAIL PROTECTED], Kay Schluehr wrote: A new cookbook recipe suggesting two decorators @throws and @catches for treatment of checked exceptions in Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498131 This might be of practical interest for some and theoretical interest for others - in particular those who know checked ex as a language feature of Java. The trouble with having to declare every possible exception that a function might throw is that it rapidly turns into a complete mess. That's why such declarations are optional in C++, and only semi-mandatory in Java. -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
In message [EMAIL PROTECTED], Bjoern Schliessmann wrote: In my C++ code, it happens so often that I forget or overread a !. And if I want to understand my functions later on, my brain quite wrinkles looking at parentheses, !s, s and ||s. Which is why C++ allows not, and and or. -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
In message [EMAIL PROTECTED], MonkeeSage wrote: I don't really see anything wrong with creating a custom class for evaluating those kinds of logical statements. It does make the code for statements more concise and easy to follow (with less binding ambiguity). Why not express everything in Conjunctive Normal Form? -- http://mail.python.org/mailman/listinfo/python-list
Need compile python code
Need compile python code, source is in html and starts with parameters: #!/bin/sh - exec python -O $0 $@ I have installed ActivePython for windows. -- http://mail.python.org/mailman/listinfo/python-list
Re: One program in different GUI Toolkits
Franz Steinhaeusler wrote: Hello NG, I have a suggestion. For simplifying learning or switching between different GUI Toolkits, I could imagine to have one short clearly presented program in different GUI Toolkits. Anybody is interested in implementing in one other GUI? We could put in on one Python wiki page for example. Thanks to your post, I have fallen in love with PythonCard. I would be happy to try to implement what you want in that. -- http://mail.python.org/mailman/listinfo/python-list
Re: grabbing random words
Another approach would be to just scrape a CS's random (5.75 x 10^30) word haiku generator. ;) import urllib import libxml2 import random uri = 'http://www.cs.indiana.edu/cgi-bin/haiku' sock = urllib.urlopen(uri) data = sock.read() sock.close() doc = libxml2.htmlParseDoc(data, None) words = [p.content for p in doc.xpathEval('//a')[8:-3]] doc.freeDoc() print random.choice(words) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Application logging to screen and file - any favorite modules (no luck on cheeseshop)
Bjoern Schliessmann wrote: metaperl wrote: Hello, I am looking for a module which has * log levels * output to stdout and file (either/or based on config) * nicely formatted log output (e.g., indentation when appropriate) Sorry for being nosey, but how'd you use indentation in a log? I guess I was thinking more along the lines of debugging. For example, if you have two nested loops, you can increase the indentation level of output as you move into each loop to show where the output is coming from. -- http://mail.python.org/mailman/listinfo/python-list
Re: re vs sre?
Lawrence D'Oliveiro wrote: I learned about Python regular expressions from the Web documentation http://docs.python.org/lib/lib.html. This describes a module named re. Then I saw some code written by a colleague, and he was using a module named sre. I checked my Python 2.4.3 installation, and sure enough, I have a module named sre as well as re. Curious, I fired up an interactive Python session, and looked to see what the docstrings were for these modules. And for the re module, the help says: re - Minimal re compatibility wrapper. See sre for documentation. and sre seems to have the more complete set of docstrings. So which one should we be using? Here's what Python 2.5 has to say on the matter: import sre __main__:1: DeprecationWarning: The sre module is deprecated, please import re. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: re vs sre?
In message [EMAIL PROTECTED], Peter Otten wrote: Lawrence D'Oliveiro wrote: I learned about Python regular expressions from the Web documentation http://docs.python.org/lib/lib.html. This describes a module named re. Then I saw some code written by a colleague, and he was using a module named sre. I checked my Python 2.4.3 installation, and sure enough, I have a module named sre as well as re. Curious, I fired up an interactive Python session, and looked to see what the docstrings were for these modules. And for the re module, the help says: re - Minimal re compatibility wrapper. See sre for documentation. and sre seems to have the more complete set of docstrings. So which one should we be using? Here's what Python 2.5 has to say on the matter: import sre __main__:1: DeprecationWarning: The sre module is deprecated, please import re. That's good. Does help(re) still say it's a compatibility wrapper? -- http://mail.python.org/mailman/listinfo/python-list
Re: CONSTRUCT - New/Old Style Classes, build-in/extension types
Steve Holden wrote: Ilias Lazaridis wrote: Steve Holden wrote: ... Though of course the easiest way to enforce your classes to new style is to begin each module with __metaclass__ = type I assume placing this in the central site import (e.g. sitecustomize.py) would collapse python? (I don't want to try it, maybe someone has an isolated instance available for trials). I don't think it would collapse Python, but since each module requires its own __metaclass__ setting it certainly wouldn't change much. I understand. Thus I cannot set __metaclass__ = object on e.g. project-level or site-level, but only module-level. . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
QuoteSQL
Why doesn't MySQLdb provide a function like this: def QuoteSQL(Str, DoWild) : returns a MySQL string literal which evaluates to Str. Needed for those times when MySQLdb's automatic quoting isn't good enough. Result = [] for Ch in str(Str) : if Ch == \0 : Ch = \\0 elif Ch == \010 : Ch = \\b elif Ch == \011 : Ch = \\t elif Ch == \012 : Ch = \\n elif Ch == \015 : Ch = \\r elif Ch == \032 : Ch = \\z elif Ch == ' or Ch == \ or Ch == \\ : Ch = \\ + Ch elif DoWild and (Ch == % or Ch == _) : Ch = \\ + Ch #end if Result.append(Ch) #end for return \ + .join(Result) + \ #end QuoteSQL -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], MonkeeSage wrote: I don't really see anything wrong with creating a custom class for evaluating those kinds of logical statements. It does make the code for statements more concise and easy to follow (with less binding ambiguity). Why not express everything in Conjunctive Normal Form? Because: (¬Can add all the literal operators ∧ Already existed a concise/unambiguous mechanism for all but negation) ├ Used existing scheme but added concise/unambiguous negation mechanism. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
mistral wrote: Need compile python code, source is in html and starts with parameters: Excuse me? #!/bin/sh - exec python -O $0 $@ Is the line break intended? I have installed ActivePython for windows. What exactly do you want? Python code is always compiled (to byte code) before it's run. Regards, Björn -- BOFH excuse #359: YOU HAVE AN I/O ERROR - Incompetent Operator error -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
MonkeeSage wrote: Why not express everything in Conjunctive Normal Form? [snip] Oh, you meant the actual form. Duh! Yeah, that would work. For some reason I was thinking you were asking why I didn't implement the standard symbols, sorry. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
Lawrence D'Oliveiro wrote: Which is why C++ allows not, and and or. Is this standards compliant? My reference (book) doesn't contain it, but g++ allows it. Regards, Björn -- BOFH excuse #441: Hash table has woodworm -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
Bjoern Schliessmann wrote: Lawrence D'Oliveiro wrote: Which is why C++ allows not, and and or. Is this standards compliant? My reference (book) doesn't contain it, but g++ allows it. The C++ standard provides _operator keywords_ (Fig. 21.8) that can be used in place of several C++ operators. (Deitel Deitel, 2001; 1082). Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Converting Perl Web Report to Python
I enjoyed Paul Barry's September article in Linux Journal entitled, Web Reporting with MySQL, CSS and Perl. It provides a simple, elegant way to use HTML to display database content without any sql markup in the cgi script. The cgi script simply calls the Mysql command line with the HTML option (-H) and the SQL script file directed to that command. This provides complete separation of the markup from the sql code. The plain vanila HTML output can be spruced up with CSS to provide more color and size control of the HTML. Could this script be easily converted to Python? How would you execute the Msql command line and direct the output to a variable for display in the cgi script? Would it be possible to easily enhance this script by allowing the user to pass in an SQL query parameter to the sql script? I attempted this in Perl by substituting the string p_1 in the where clause of the sql code but I could not substitute this string with the value in the cgi code (ie. $query =~ s/p_1/value_variable/;). Perhaps it would be easier in Python? Also, would the user supplied parameter be a security issue? Thanks! Below is a link to the article: http://delivery.acm.org/10.1145/116/1152907/8281.html?key1=1152907key2=9804109511coll=ACMdl=ACMCFID=15151515CFTOKEN=6184618 -- http://mail.python.org/mailman/listinfo/python-list
Re: QuoteSQL
Lawrence D'Oliveiro wrote: Why doesn't MySQLdb provide a function like this: Because the author has read PEP 8? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and checked exceptions
This might be of practical interest for some and theoretical interest for others - in particular those who know checked ex as a language feature of Java. The trouble with having to declare every possible exception that a function might throw is that it rapidly turns into a complete mess. That's why such declarations are optional in C++, and only semi-mandatory in Java. I agree with you that they are a mess, and I usually wrap them RuntimeExceptions. Why do you call them semi-mandatory? diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
Bjoern Schliessmann писал(а): mistral wrote: Need compile python code, source is in html and starts with parameters: Excuse me? #!/bin/sh - exec python -O $0 $@ Is the line break intended? I have installed ActivePython for windows. What exactly do you want? Python code is always compiled (to byte code) before it's run. Regards, Björn -- Just to comple python ode - it creates html page, nothing more, nothing else.. Just generate one html page. mistral -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
Bjoern Schliessmann писал(а): mistral wrote: Need compile python code, source is in html and starts with parameters: Excuse me? #!/bin/sh - exec python -O $0 $@ Is the line break intended? I have installed ActivePython for windows. What exactly do you want? Python code is always compiled (to byte code) before it's run. Regards, Björn -- Just to comple python ode - it creates html page, nothing more, nothing else.. Just generate one html page. mistral -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils on Windows with VC++ 8
Rob Williscroft wrote in news:Xns9846DDC7A18E0rtwfreenetREMOVEcouk@ 216.196.109.145 in comp.lang.python: That's yet another option. Somebody reported that the compiler in the .NET SDK won't support generating optimized code, though. That's a problem for some people. I belive that was true Academic releases of Visual Studio, AIUI it was never true of the 7.1 compiler that came with .NET 1.1 SDK's. ... a 106 MB download later ... Strike that. My belief was incorrect, the SDK comes with the Standard compiler that doesn't understand the /O... options that the Optimizing compiler that comes with Visual Studio does. Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: anybody using python 2.5 that raises error while importing?
John Machin wrote: daniel wrote: there's a dll extension used to be imported with no error under version 2.4.3, but the new python complains that the name of the module can't be found. seems not mentioned in the official documentation, any work around to fix the issue without switching back to the old version? thank you for your reply.. Did/does its name end in .dll or in .pyd? It ends in .dll Have you procured a new one (necessary when there's a change of minor version number) and installed it in the right place? My output of python -V shows 2.5c2 Can you tell us the name of the module, and the path to the DLL/PYD The dll is distributed with a third party library, it claimed to be compatible with 2.4, It was installed at d:\ on my box, and the path had been added to my PYTHONPATH variable. that is/was imported by Python 2.4? yep, it works very well with python 2.4, so, I'm just wondering if there is a fix for using with 2.5 Have you contacted the author(s) of the module? uh.. not yet, because they clearly mentioned that in the doc. Have you installed Python 2.5 in its own directory e.g. c:\python25 (the default)? Python 2.4, same question? Have you uninstalled 2.4? I already uninstalled the version 2.4. and put python25 in drive d:. there's probably no problem with my environment variables, maybe I should check for a updated version of python. thanks again. daniel Regards, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and checked exceptions
Peter Otten wrote: Kay Schluehr wrote: A new cookbook recipe suggesting two decorators @throws and @catches for treatment of checked exceptions in Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498131 This might be of practical interest for some and theoretical interest for others - in particular those who know checked ex as a language feature of Java. Probably not what you wanted: test() Raises UncheckedExceptionError(exceptions.ZeroDivisionError) - OK Raises ZeroDivisionError - OK Traceback (most recent call last): File stdin, line 1, in ? File checked_exceptions.py, line 134, in test test4(3,2) UnboundLocalError: local variable 'test4' referenced before assignment Peter Thanks, I fixed this. Kay -- http://mail.python.org/mailman/listinfo/python-list
f2py on windows tutorials
Hello, Compiling f2py extensions in Linux is a trivial task, You can even automate it with distutils. Now, in a Windows machine this does not seem to be an easy task. At least, I could not find any decent tutorial on how to do it. Is there a way to do this? Can some one point me to a tutorial., please? I have tried some approaches: mingw, xmingw (cross-compiling from Linux) and Python enthought edition (which is supposed to come preconfigured to enable people to use Scipy tools, such as f2py) Withouth success. Anyone out there knows how to do this? Anyone from the Scipy dev team care to document it? Flávio -- http://mail.python.org/mailman/listinfo/python-list
Re: One program in different GUI Toolkits
On Wed, 20 Sep 2006 08:27:30 +0200, Franz Steinhaeusler wrote (in article [EMAIL PROTECTED]): What about for example wxProject? What about something that could be actually useful for end-users? :- E.g. a GUI wrapper for Httrack? The back-end is already there: http://www.satzbau-gmbh.de/staff/abel/httrack-py/ So the work could really focus on the GUI. BTW: There's a book from MITP Python und GUI Toolkits (in German) that shows how to implement a given example program with Tkinter, Qt, wxWidgets and GTK+2. Sincerely, Wolfgang Keller -- My email-address is correct. Do NOT remove .nospam to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: QuoteSQL
Lawrence D'Oliveiro wrote: Why doesn't MySQLdb provide a function like this: def QuoteSQL(Str, DoWild) : returns a MySQL string literal which evaluates to Str. Needed for those times when MySQLdb's automatic quoting isn't good enough. Presumably because you're expected to use placeholders. When is that not good enough? elif Ch == ' or Ch == \ or Ch == \\ : Ch = \\ + Ch Always sad to see an SQL DBMS willfully violate the SQL standard. - Anders -- http://mail.python.org/mailman/listinfo/python-list
Re: anybody using python 2.5 that raises error while importing?
daniel wrote: John Machin wrote: daniel wrote: there's a dll extension used to be imported with no error under version 2.4.3, but the new python complains that the name of the module can't be found. seems not mentioned in the official documentation, any work around to fix the issue without switching back to the old version? thank you for your reply.. Did/does its name end in .dll or in .pyd? It ends in .dll Have you procured a new one (necessary when there's a change of minor version number) and installed it in the right place? My output of python -V shows 2.5c2 Huh? The question was in effect Have you obtained a NEW version of the *DLL*? This is necessary when you upgrade from Python 2.4 to Python 2.5. Can you tell us the name of the module, and the path to the DLL/PYD The dll is distributed with a third party library, it claimed to be compatible with 2.4, It was installed at d:\ on my box, and the path had been added to my PYTHONPATH variable. Do you mean that the full path to the module was d:\the_module_name.dll ? that is/was imported by Python 2.4? yep, it works very well with python 2.4, so, I'm just wondering if there is a fix for using with 2.5 No, you can't use a 2.4-compatible binary module with 2.5. Have you contacted the author(s) of the module? uh.. not yet, because they clearly mentioned that in the doc. They clearly mentioned *what* in the doc? Have they yet announced availibility of a 2.5-supported version of their software? Have you installed Python 2.5 in its own directory e.g. c:\python25 (the default)? Python 2.4, same question? Have you uninstalled 2.4? I already uninstalled the version 2.4. and put python25 in drive d:. there's probably no problem with my environment variables, maybe I should check for a updated version of python. Huh, again? Firstly, 2.5 final has been released -- you should really subscribe to the python-announce mailing list so that you don't need to check for major events. Secondly, upgrading from 2.5c2 to 2.5 is generally a good thing, but it won't solve your missing dll problem. From 2.5 onwards, a Python extension module must be named .pyd, it can't be named .dll. You could try renaming it, but you are likely to get this error when you try to import it in 2.5: ImportError: Module use of python24.dll conflicts with this version of Python. IOW, the version compatibility problem. Bottom line: you need to get an updated extension module from the software supplier. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Spliting a string on non alpha characters
Hello! I'm relatively new to python but I already noticed that many lines of python code can be simplified to a oneliner by some clever coder. As the topics says, I'm trying to split lines like this : 'foo bar- blah/hm.lala' - [foo, bar, blah, hm, lala] 'foobbbar.. xyz' - [foo, bbbar, xyz] obviously a for loop catching just chars could do the trick, but I'm looking for a more elegant way. Anyone can help? -- http://mail.python.org/mailman/listinfo/python-list
help with debugging a ctypes problem
I'm no c programmer, and I'm a ctypes newbie. I'll frame my problem as simply as I can. Sorry if it's too much or not enough info. I don't expect an explicit answer (but maybe), just help figuring out how to debug. WinXP, python 2.4.2 I'm using ctypes to access functions in a commercial dll. A certain function takes five arguments, foo(a, b, c, d, e). The last argument, e, is an integer that serves as a bit coded options flag. Zero means no option, 1+2+4 means the first three options combined, etc. I can call foo() successfully if e=c_int(0). However, if e=3, the function does not work. Execution of the python program continues after the call, no errors are raised, but foo() has not done its thing. If I now call bar(x, y, z) after foo(), two things happen. 1. The dll raises an error reporting that argument x is invalid 2. Python reports that too many bytes (4) have been passed to bar() I've checked the types of all the variables a million times, and they are correct according to the docs. The vendor sent me a c program that they claim works. It looks like a translation of mine. I can't run theirs, because I can't figure out how to compile it (I'm don't do c; I do have MinGW; the code was designed for MSVC; I'm lost). I'm suspecting that foo() screws up a stack somewhere. That might explain why bar() chokes on the *first* parameter, while it thinks that the number of arguments is wrong when it gets to the *last*. How can I debug this? Can I view the appropriate stack? What/where would I find it? Any other ideas or advice? etc? thanks, -gary -- http://mail.python.org/mailman/listinfo/python-list
IDLE - Customizing output format
IDLE has an output format like this: object type 'object' type type 'type' object.__class__ type 'type' object.__bases__ How can I customize it to become like that: object type 'object' type type 'type' object.__class__ type 'type' object.__bases__ or that: object : type 'object' type : type 'type' object.__class__ : type 'type' object.__bases__ (preferably without modifying code) . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Spliting a string on non alpha characters
I'm relatively new to python but I already noticed that many lines of python code can be simplified to a oneliner by some clever coder. As the topics says, I'm trying to split lines like this : 'foo bar- blah/hm.lala' - [foo, bar, blah, hm, lala] 'foobbbar.. xyz' - [foo, bbbar, xyz] obviously a for loop catching just chars could do the trick, but I'm looking for a more elegant way. Anyone can help? 1st, I presume you mean that you want back ['foo', 'bar', 'blah', 'hm', 'lala'] instead of [foo, bar, blah, hm, lala] (which would presume you have variables named as such, which is kinda funky) That said... Well, I'm sure there are scads of ways to do this. I know regexps can do it fairly cleanly: import re r = re.compile(r'\w+') s = 'foo bar- blah/hm.lala' s2 = 'foobbbar.. xyz' r.findall(s) ['foo', 'bar', 'blah', 'hm', 'lala'] r.findall(s2) ['foo', 'bbbar', 'xyz'] The regexp in question (r'\w+') translates to one or more 'word' character. The definition of a 'word' character depends on your locale/encoding, but would at a minimum include your standard alphabet, and digits. If you're not interested in digits, and only want 26*2 letters, you can use r = re.compile(r'[a-zA-Z]+') instead (which would be one or more letters in the set [a-zA-Z]). -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Spliting a string on non alpha characters
I'm relatively new to python but I already noticed that many lines of python code can be simplified to a oneliner by some clever coder. As the topics says, I'm trying to split lines like this : 'foo bar- blah/hm.lala' - [foo, bar, blah, hm, lala] 'foobbbar.. xyz' - [foo, bbbar, xyz] obviously a for loop catching just chars could do the trick, but I'm looking for a more elegant way. Anyone can help? A simple regular expression would work: import re s = 'foo bar- blah/hm.lala' re.findall(r\w+,s) ['foo', 'bar', 'blah', 'hm', 'lala'] -- http://mail.python.org/mailman/listinfo/python-list
Relative import first impressions
Now 2.5 is out, and we have a syntax for explicit relative imports (PEP 328, http://www.python.org/dev/peps/pep-0328/, in case anyone wasn't paying attention). The long-term plan is that the classical import syntax becomes absolute import only, so that all imports are explicitly one or the other. You can only use relative import from within packages. Trying to import a top-level module relatively from within same directory, produces the exception ValueError: Relative importpath too deep. There's a certain logic to that: You can just omit from . and do a regular absolute import. However, that spells bad news for modules that are both contained within packages, and executed from the top level as well. Accessing the same module both from within a package and outside it may seem like a bad idea, and in many ways, it is. You may get a double import of the same module with subtle, mysterious bugs to follow, when e.g. you suddenly have two copies of the same class, and isinstance(obj,mymodule.Cls) fails unexpectedly. But it's quite common all the same: The if __name__ == __main__: idiom is often used, even within packages. But that is currently incompatible with using relative imports. It seems to me that unless we rethink the main idiom competely (which may not be a bad idea by the way, for the reasons given above), relative imports at the top level will need to be allowed. Another addition I'd like to see it the import .foo form. Currently only from-imports have a relative form. The argument against is that import X binds the name X, and it's not clear which name the relative import binds. I move that it's blindingly obvious: import .foo binds foo, equivalent to from . import foo. Did anyone really expect the name .foo to be bound? It's not a big deal though, as you only need to type from . once per module anyway. Using another improvement in 2.5, you can now write: from . import ( this, that, ) - Anders -- http://mail.python.org/mailman/listinfo/python-list
Re: Building things with setup.py
James Stroud schrieb: COMMENTARYThough great for self development, I'm not so sure such lessons should be necessary to build these tools./COMMENTARY Yes. The lesson you should take from this is: don't try to be smarter than the authors of the software. It should build out of the box, if you follow the build instructions literally. Deviate to the tiniest from the instructions, and you are on your own. If it doesn't work out of the box even though you followed the instructions, don't try to fix it. You didn't write it, fixing it will be a huge effort. Instead, get help from somebody, and/or report a bug. Always strive for the simplest possible setup. If you find that you have to customize something, and the instructions did not tell you to do so, question this customization. It is likely wrong or unnecessary. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: anybody using python 2.5 that raises error while importing?
thank you so much for your help.. I've got no idea about pyd or dll stuff, started to learn python just several weeks ago. so the implementation rules of python extension module must have been changed, for now, I have to wait for the new release of that module and switch back to python 2.4 to get my work done. thanks again.. daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
mistral wrote: Just to comple python ode - it creates html page, nothing more, nothing else.. Just generate one html page. I *think* this is what you want: python -O -m py_compile file.py python file.pyo See: http://docs.python.org/lib/module-pycompile.html Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
ANN: PyDSTool v0.83.3 released
We are pleased to announce version 0.83.3 of our open-source simulation, modeling, and analysis package PyDSTool. New features include improved graphical capabilities in the PyCont bifurcation and continuation sub-package and its interface with AUTO, and better support for domain bound enforcement on state variables and parameters. There are several bug fixes and general improvements to the API in this release too. Please see http://pydstool.sourceforge.net for details and documentation. Regards, Rob, Drew, and Erik. Center for Applied Mathematics, Cornell University. ** PyDSTool is an integrated simulation, modeling and analysis package for dynamical systems, written in Python (and partly in C). It is being developed at Cornell University, and the source code is available under the terms of the BSD license. PyDSTool runs on Linux, Windows, and Macs, and aims to have a minimal number of package dependencies. Currently, it requires (old) SciPy, Numarray, and Matplotlib. -- http://mail.python.org/mailman/listinfo/python-list
Running Python script from C++ code(.NET)
Hello, folks! A trivial question - I have a working Python script that I have to invoke from C++ code. No fancy stuff - just run the whole script with its parameters. No callbacks, no signalling - nada, just stupid,primitive, straightforward call. And while there is a lot of help on embedding, I could not find out how to run script as a whole.SOS -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Python script from C++ code(.NET)
volcano wrote: Hello, folks! A trivial question - I have a working Python script that I have to invoke from C++ code. No fancy stuff - just run the whole script with its parameters. No callbacks, no signalling - nada, just stupid,primitive, straightforward call. And while there is a lot of help on embedding, I could not find out how to run script as a whole.SOS In C#: http://groups.google.com/group/comp.lang.python/browse_frm/thread/da2a675da29b0bd/197b6a89095ef930?lnk=stq=rnum=4#197b6a89095ef930 hth Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeline for Python?
In article [EMAIL PROTECTED], crystalattice [EMAIL PROTECTED] wrote: From: Sebastian Bassi [EMAIL PROTECTED] Date: Thurs, Aug 31 2006 7:51 am Subject: Re: Timeline for Python? Groups: comp.lang.python I am working on a Python book, since it could be completed in about a year (writing time + edition + publishing) or more, I would like to know what version to target since I don't want to release a book that will be outdated just after is printed. : So, if the book is published in October 2007, should feature Python 3 or Python 2.5? I'd write for 2.4, even though 2.5 should be coming out shortly. There aren't many significant changes to the whole language between 2.4 and 2.5. Probably the best thing is write for 2.4 and have a sidenote stating where 2.5 operates differently. Speaking as the co-author of _Python for Dummies_: That's bad advice -- there are three Python books already out (or out within the next couple of weeks) that target 2.5: _Python in a Nutshell_, _Core Python_, and _Python for Dummies_. : OTOH, I do agree that any book written should include diferences between 2.5 and earlier versions for the benefit of people needing to target earlier or multiple versions. sorry to chime in 2 weeks late here, but i second aahz's opinion here, as well as have some thoughts of my own: 1. never write against older versions of Python... you will only obsolete your book even faster (well, sooner) 2. with respect to 2.4 vs. 2.5, there are some significant changes as aahz has pointed out; otherwise it would be 2.4.4. 3. personally speaking, i'm against targeting versions altogether. i guess i am a bit biased because in Core Python Programming, the focus is the core part of the Python language, hence it should be as generic to specific versions as possible. i've made serious attempts to avoid being locked-in to any particular release. yes, i cover through 2.5, but also include stuff that have already been slated for 2.6 and 2.7. what, if you can discuss, is the topic of *your* book? 4. with that said, i have taken aahz's final remark above quite seriously... i've gone to great lengths to add tags all over Core Python which state things like, 2.2, 2.5-2.7, 2.0, etc. to indicate when certain features were added, removed, or changed in the language. this will support readers who are users of any version of Python. and with a sigh of relief, i can happily tell everyone that Core Python did finally hit the streets this week! (more info at the link below) cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help
From: Rrajal [EMAIL PROTECTED] Date: Mon, Sep 18 2006 9:50 am Subject: Re: Help Groups: comp.lang.python Hi there, I am new in this subject so could you please tell me from where I can get help (or good e-book) of python? do you have some kind of programming background? if so, good intro books include Hetland's Beginning Python, Pilgrim's Dive into Python, and O'Reilly's Learning Python. there is an online version of Dive at http://diveintopython.org if you're looking for something more comprehensive, i wrote Core Python Programming, but it is much longer than the others, so if you want a quick intro, it would not be for you. here's a nice list and description of most Python books: http://wiki.python.org/moin/PythonBooks for those are are new to programming altogether, you can try Dawson's Absolute Beginner or the Learn to Program by Gauld, but since it's dated, it's best to check out Alan's tutorial at:http://www.freenetpages.co.uk/hp/alan.gauld/ cheers! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com -- http://mail.python.org/mailman/listinfo/python-list
Re: A critique of cgi.escape
Lawrence D'Oliveiro wrote: So I think the default for the second argument to cgi.escape should be changed to True. Or alternatively, the second argument should be removed altogether, and quotes should always be escaped. you're confused: cgi.escape(s) is designed to be used for ordinary text, cgi.escape(s, True) is designed for attributes. if you use the code the way it's intended to be used, it works perfectly fine. Can changing the default break existing scripts? I don't see how. It might even fix a few lurking bugs out there. I'm not sure this every time I don't immediately understand something, I'll write a change proposal instead of reading the library reference approach is healthy, really. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Fatal error after RE-installing Python 2.3.4
What happens when you run C:\Python2.3\python.exe from the command line (or the equivalent path)? How about pythonw.exe (or the windowed equivalent, not sure about the naming)? Are .py and .pyw files displayed with the correct icons? Yes. When installing Python packages, is Python 2.3 detected as the default installation? Yes Finally, does your $PATH include the Python directory? That could also cause problems if it doesn't. I doubt that the path would cause this type of problem. If the path wasn't found the exe wouldn't run, and this error wouldnt be displayed. And, what sorts of warnings did PyChecker display? Missing files/modules? Missing modules, mostly, but Pychecker isnt a concern at this point. It was merely what prompted me to re-install everything. All of my tests scripts could be executed via python my script.py, from a cmd console before I re-installed. I have unisntaleld re-installed Python 2.3.4 many times- using different installers, to eliminate a corrupted installation medmium, but they all result in the same error when I run python from a cmd console. -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Python script from C++ code(.NET)
Gerard Flanagan wrote: volcano wrote: Hello, folks! A trivial question - I have a working Python script that I have to invoke from C++ code. No fancy stuff - just run the whole script with its parameters. No callbacks, no signalling - nada, just stupid,primitive, straightforward call. And while there is a lot of help on embedding, I could not find out how to run script as a whole.SOS In C#: http://groups.google.com/group/comp.lang.python/browse_frm/thread/da2a675da29b0bd/197b6a89095ef930?lnk=stq=rnum=4#197b6a89095ef930 hth Gerard Thanks for fast response, alas - it did not! My problem is - application in C++ used to use external application, which does not work well. So I sort of reproduced the functionality in Python script, but now I am stuck, unable to run it properly. -- http://mail.python.org/mailman/listinfo/python-list
Re: no-installation version of python
[EMAIL PROTECTED] wrote: Is there a stand-alone version of python out there that I can package with my scripts so that I don't have to bother with something like py2exe? why not just ship the standard python interpreter with your applications? just make a copy of the c:\python24 (or 25) installation directory, and add your scripts and the Python core DLL (which is usually installed under c:\windows\system32\python24.dll (or 25) to it. you may want to tweak your code to explicitly set sys.path to something nice, so that global PYTHONPATH settings (etc) won't interfere with your application. for extra bonus points, remove the stuff your application doesn't need. or you could just use py2exe. or if you just want EXE files that you can use with an existing Python install, use exemaker: http://effbot.org/zone/exemaker.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Fatal error after RE-installing Python 2.3.4
deleted the core 2.3.4 distribution [from where? how?] or uninstalled? Uninstalled Was c:\windows\system32\python23.dll blown away? Yes, as part of the uninstall process. Are you installing it for all users or for a single user? ALl users, using Admin priveledges Do a search for python23.dll -- you may find two. This can happen if you have switched from one way to the other way. DLL in c:\windows\system32 = all users. DLL somewhere else e.g. c:\python23 = specific user. Check how this is set up on other working boxes. Check date and size while you are doing that. Also check what they have on their system path compared to yours. will try on Monday My path is the same. We all followa detailed installation, tools configuration procedure/. I've compared my path to one other workign machine. Have you tried running it with the -v commandline arg to see how far it gets before crashing? No- will try it on Monday Oddly enough, when I run Python.exe from the Program Files menu, it launches just fine. Yeah, different path. Some thoughts and questions: 1. Telling us what the allegedly spurious pychecker warnings were would be a good idea. pychecker isn't really a concern at this point- and has ben uninstalled (actually deleted, since there is no installer/uninstaller for this package.) But I was getting lots of missing module warnings, which two of my co-workers did not get. 2. I don't understand the my job depends part. Are you responsible for providing your own computer and installing your own tool-chain on it?? No Is this an initiative test? No. Can't you get the admin(s) to install a clean tested kit for you? No. 3. What is this PC's history? Has it been used successfully in this environment before you turned up? Yes- I have been using it to run python scripts for the last 2 weeks. When I saw the pychecker anomally, I decided to rein-install Python a few of the packages. Are all the other engineers using the same configuration? yes 4. Is Python 2.3.5 a possibility? No, not in practice. But I tried installing 2.3.5 to see what would happen. Same problem. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Python script from C++ code(.NET)
volcano wrote: Gerard Flanagan wrote: volcano wrote: Hello, folks! A trivial question - I have a working Python script that I have to invoke from C++ code. No fancy stuff - just run the whole script with its parameters. No callbacks, no signalling - nada, just stupid,primitive, straightforward call. And while there is a lot of help on embedding, I could not find out how to run script as a whole.SOS In C#: http://groups.google.com/group/comp.lang.python/browse_frm/thread/da2a675da29b0bd/197b6a89095ef930?lnk=stq=rnum=4#197b6a89095ef930 hth Gerard Thanks for fast response, alas - it did not! My problem is - application in C++ used to use external application, which does not work well. So I sort of reproduced the functionality in Python script, but now I am stuck, unable to run it properly. Maybe my understanding is wrong, but can't managed (.NET) C++ call into any other managed assembly, in this case (I think) System.Diagnostics? Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Python script from C++ code(.NET)
Gerard Flanagan wrote: volcano wrote: Gerard Flanagan wrote: volcano wrote: Hello, folks! A trivial question - I have a working Python script that I have to invoke from C++ code. No fancy stuff - just run the whole script with its parameters. No callbacks, no signalling - nada, just stupid,primitive, straightforward call. And while there is a lot of help on embedding, I could not find out how to run script as a whole.SOS In C#: http://groups.google.com/group/comp.lang.python/browse_frm/thread/da2a675da29b0bd/197b6a89095ef930?lnk=stq=rnum=4#197b6a89095ef930 hth Gerard Thanks for fast response, alas - it did not! My problem is - application in C++ used to use external application, which does not work well. So I sort of reproduced the functionality in Python script, but now I am stuck, unable to run it properly. Maybe my understanding is wrong, but can't managed (.NET) C++ call into any other managed assembly, in this case (I think) System.Diagnostics? Gerard My application is written in regular C++:( -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
MonkeeSage писал(а): mistral wrote: Just to comple python ode - it creates html page, nothing more, nothing else.. Just generate one html page. I *think* this is what you want: python -O -m py_compile file.py python file.pyo See: http://docs.python.org/lib/module-pycompile.html Regards, Jordan -- this not work for me, show compilation error. Is there simple way compile pythone file? its absolutely unclear with command line. Just show me exact command I need run(from python interactive shell?) -- http://mail.python.org/mailman/listinfo/python-list
Re: what's new missing
David Isaac [EMAIL PROTECTED] wrote: What's New document for Python 2.5? http://docs.python.org/dev/whatsnew/whatsnew25.html pretends to hold it, but the links are corrupt. It's without /dev/ -- Lawrence - http://www.oluyede.org/blog Nothing is more dangerous than an idea if it's the only one you have - E. A. Chartier -- http://mail.python.org/mailman/listinfo/python-list
Re: what's new missing
Alan Isaac [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Where does one get the What's New document for Python 2.5? http://docs.python.org/dev/whatsnew/whatsnew25.html pretends to hold it, but the links are corrupt. OK, here it is: http://docs.python.org/whatsnew/whatsnew25.html Sorry for the noise. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
mistral wrote: this not work for me, show compilation error. Is there simple way compile pythone file? its absolutely unclear with command line. Just show me exact command I need run(from python interactive shell?) OK... # cd to where the file.py is $ cd /some/dir # start python interactively, enable optimized compiling $ python -O ... # import your file.py -- if this doesn't work then # your file has errors and will not compile -- # if it works then your file is now compiled -- # file.pyo should now exist with file.py import file # you can also do it explicitly -- # import the compiler import py_compile py_compiler.compile('file.py') If that still doesn't work, show us the error, or we can't help you very easily. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: newbe's re question
These are csound files. Csound recently added python as a scripting language and is allowing also allowing csound calls from outside of csound. The nice thing about csound is that instead of worrying about virus and large files it is an interpiter and all the files look somewhat like html. 4,000 virus free instruments for $20 is available at http://www.csounds.com and the csound programming book is also available. The downside is that csound is can be realy ugly looking (that is what I am trying to change) and it lets you write ugly looking song code that is almost unreadable at times (would look nice in a grid) http://www.msn.com .. Frederic Rentsch wrote: [EMAIL PROTECTED] wrote: Frederic Rentsch wrote: [EMAIL PROTECTED] wrote: Frederic Rentsch wrote: [EMAIL PROTECTED] wrote: All I am after realy is to change this reline = re.line.split('instr', '/d$') into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may not be at the end of the line starting with ; until the end of the line including white spaces.. this is a corrected version from http://python-forum.org/py/viewtopic.php?t=1703 thanks in advance the hole routine is down below.. [code] def extractCsdInstrument (input_File_Name, output_File_Name, instr_number): takes an .csd input file and grabs instr_number instrument and creates output_File_Name f = open (input_File_Name , 'r')#opens file passed in to read f2 = open (output_File_Name, 'w') #opens file passed in to write instr_yes = 'false' #set flag to false for line in f: #for through all the lines if instr in line: #look for instr in the file if instr_yes == 'true':#check to see if this ends the instr block break#exit the block reline = re.line.split('instr', '/d$') #error probily split instr and /d (decimal number into parts) $ for end of line number = int(reline[1]) #convert to a number maybe not important if number == instr_number:#check to see if it is the instr passed to function instr_yes = true: #change flag to true because this is the instr we want if instr_yes = true:#start of code to copy to another file f2.write(f.line) #write line to output file f.close #close input file f2.close [/code] Eric, From your problem description and your code it is unclear what exactly it is you want. The task appears to be rather simple, though, and if you don't get much useful help I'd say it is because you don't explain it very well. I believe we've been through this before and your input data is like this data = ''' CsoundSynthesizer; ; test.csd - a Csound structured data file CsOptions -W -d -o tone.wav /CsOptions CsVersion;optional section Before 4.10 ;these two statements check for After 4.08 ; Csound version 4.09 /CsVersion CsInstruments ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin /CsInstruments CsScore ; originally tone.sco f1 0 8192 10 1 i1 0 1 2 1000 ;play one second of one kHz tone e /CsScore /CsoundSynthesizer Question 1: Is this your input? if yes: Question 1.1: What do you want to extract from it? In what format? if no: Question 1.1: What is your input? Question 1.2: What do you want to extract from it? In what format? Question 2: Do you need to generate output file names from the data? (One file per instrument?) if yes: Question 2.1: What do you want to make your file name from? (Instrument number?) Regards Frederic I want to pass the file name to the subroutine and return a comment string if it is there maybe it should be simplier. I probily should have the option of grabbing the comment in other related routines. I am pretty ambitious with the main program. I did notice some code in tcl that would be usefull to the app If I compile it.. I am probily not ready for that though.. http://www.dexrow.com Eric, I'm beginning to enjoy this. I'm sure we'll sort this out in no time if we proceed methodically. Imagine you are a teacher and I am your student. This is a quiz. I have to take it and you need to explain to me the problem you want me to solve. If you
Re: Need compile python code
MonkeeSage wrote: import py_compile py_compiler.compile('file.py') ^^^ Should be: py_compile.compile('file.py') -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
MonkeeSage wrote: mistral wrote: this not work for me, show compilation error. Is there simple way compile pythone file? its absolutely unclear with command line. Just show me exact command I need run(from python interactive shell?) OK... # cd to where the file.py is $ cd /some/dir # start python interactively, enable optimized compiling $ python -O ... # import your file.py -- if this doesn't work then # your file has errors and will not compile -- # if it works then your file is now compiled -- # file.pyo should now exist with file.py import file # you can also do it explicitly -- # import the compiler import py_compile py_compiler.compile('file.py') If that still doesn't work, show us the error, or we can't help you very easily. Regards, Jordan --- No, something is wrong there. what I need is just compile one python file which will generate html page, with parameters: exec python -O $0 $@ just need simple way do this(script is correct), i will not set any patches anywhere, can i do this wrom normal GUI? -- http://mail.python.org/mailman/listinfo/python-list
wxmsw26uh_vc.dll not found when using wxAgg backend
Hello, Copy wxmsw26uh_vc.dll inC:\python24\lib\site-packages\matplotlib\backends.To find wxmsw26uh_vc.dll, you can downloadwxPython2.6-win32-unicode-2.6.3.3-py24.exe,and execute in aspecific directory and extract the file wxmsw26uh_vc.dll(C:\...\wx-2.6-msw-unicode\wx) Regards, Michel -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
On 23 Sep 2006 12:24:58 -0700, mistral wrote No, something is wrong there. what I need is just compile one python file which will generate html page, with parameters: exec python -O $0 $@ This is not a python script. It appears to be a Unix shell script that calls a python script. Maybe it would help if you told us exactly what you're trying to accomplish and why you think you need to compile python code. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: Need compile python code
mistral wrote: No, something is wrong there. what I need is just compile one python file which will generate html page, with parameters: exec python -O $0 $@ just need simple way do this(script is correct), i will not set any patches anywhere, can i do this wrom normal GUI? Hmmm... Are you talking about _RUNNING_ python scripts? Is that what you mean by compile -- you mean execute? Is that what this broken shell script means? exec python -O $0 $@ You don't need exec, the double quote on every word breaks it, and passing $0 (which is the shell script itself) to python is sure to break. Try this: #!/bin/sh python -O $@ Then: $ run_python.sh file.py arg1 arg2 arg3 Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list
Re: anybody using python 2.5 that raises error while importing?
Dennis Lee Bieber schrieb: On 23 Sep 2006 09:24:09 -0700, daniel [EMAIL PROTECTED] declaimed the following in comp.lang.python: so the implementation rules of python extension module must have been changed, for now, I have to wait for the new release of that module and No change... For YEARS the rule has been: Changes in the first decimal place (version m.n.o - if n changes, new binaries are needed; changes in o are just bug fixes and don't change the binary interface; abandon all hope if m changes G) of a Python version almost ALWAYS require 3rd party binary extensions to be rebuilt. You should read the entire thread. He couldn't import the extension module because it ends in .dll; this was a change introduced in Python 2.5: the module must end in .pyd now. That rule had not been there for YEARS. Of course, had he renamed the file, it then would have complained that he's running a 2.4 extension module in 2.5; *that* rule had been there for YEARS. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: f2py on windows tutorials
Flavio wrote: Hello, Compiling f2py extensions in Linux is a trivial task, You can even automate it with distutils. Now, in a Windows machine this does not seem to be an easy task. At least, I could not find any decent tutorial on how to do it. Is there a way to do this? Can some one point me to a tutorial., please? I have tried some approaches: mingw, xmingw (cross-compiling from Linux) and Python enthought edition (which is supposed to come preconfigured to enable people to use Scipy tools, such as f2py) Withouth success. Anyone out there knows how to do this? Anyone from the Scipy dev team care to document it? shrug It's worked fine for me using Enthon (which comes with mingw and g77, things you will need at minimum). What versions of Enthon and f2py are you using? What exactly did you try? What errors are you seeing? How are you trying to compile your modules, i.e. with just the f2py command or are you building a setup.py file? Did you pass --compiler=mingw --fcompiler=gnu to your build command? -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Strange __future__ behavior in Python 2.5
My understanding of the __future__ statement is that you may say something like: from __future__ import foo, bar to enable more than one feature. However, this does not seem to be working properly in 2.5; it behaves as expected when typed into the interactive interpreter, but not when it is in a module. When I try to import the following module: from __future__ import with_statement, division, absolute_import def bar(): print 5/3 with open('asdf') as f: for line in f: print line.strip() I get a warning that 'with' will soon be a reserved keyword, and a SyntaxError on the line with the with statement, so obviously, the __future__ statement is not working. When I change the first line to: from __future__ import with_statement from __future__ import division,absolute_import then the with statement works fine. However, the true division also works fine, so apparently making multiple __future__ imports on one line works for division, but not for with_statement. Is this a bug, or am I misunderstanding something? I'm using the final release of Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) on Mac OS X. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for opinions
crystalattice a écrit : I've been working on a game for several months but now I'm thinking I may be going about it the wrong way. It's an online RPG designed to recreate a pen paper session, kind of like the OpenRPG project. Originally I planned on doing something like OpenRPG with a Python app that contained everything. But I'm thinking that approach may not be necessary. Since the game would use the Internet for everyone to play it, maybe it would be easier/better to just make a web app w/ Python underpinnings. That way I wouldn't have to worry about making a Python GUI and other standalone features that would have to be installed on each players computer; they could just interact via a web browser and IM. The code I've made so far is just a text-based proof-of-concept for the character generation to make sure I have the logic correct. I've only been designing a GUI for the last few weeks and trying different things like Tkinter and wxPython, so building a whole web app won't set me back any. With that in mind, I'm looking for opinions from more experienced programmers. For this project, do you think I should continue w/ building a stand alone program or do you think making something out of Django/Turbogears would be better? I have few experience with RPG softwares, but if your domain logic si anything more than trivially complex, it's always better to keep it as decoupled as possible from the user interface (unless of course the user interface actually is the domain !-). FWIW, this doesn't prevent you from using a web framework as the front-end... -- http://mail.python.org/mailman/listinfo/python-list
Re: help with debugging a ctypes problem
help figuring out how to debug ... ctypes ... a commercial dll. A certain function takes five arguments, foo(a, b, c, d, e). Can I view the appropriate stack? ... Any other ideas or advice? etc? Did you call the foo of _cdecl ctypes.cdll or the foo of _stdcall = ctypes.windll? What is the sizeof each argument type? Preferably fetched by compiling some C to printf them? Would it help to call C in another Dll to return the stack pointer, so Python could print the stack? -- http://mail.python.org/mailman/listinfo/python-list
Re: returning None instead of value: how to fix?
sam a écrit : i am starting to experiment with recursion, and decided to write a fairly trivial little program which took a float as input, then called a function to halve it recursively until it was less than 1: And forgot to return the result from the recursive call, I guess ?-) -- http://mail.python.org/mailman/listinfo/python-list
Reverse a String?
Is my mind playing tricks on me? I really remember being able to reverse a string as in: text='greg' print text.reverse() 'gerg' Is it possible thats in some Python install and not in others? I just switched to linux. In any case, can we get that added? Here's my workaround for now: def reverse(text): return ''.join([text[i] for i in range(len(text)-1,-1,-1)]) -- Gregory Piñero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse a String?
Gregory Piñero wrote: Is my mind playing tricks on me? I really remember being able to reverse a string as in: text='greg' print text.reverse() 'gerg' Is it possible thats in some Python install and not in others? I just switched to linux. In any case, can we get that added? Not in that form, no, since this already exists: text[::-1] -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: returning None instead of value: how to fix?
Neil Cerutti a écrit : (snip) It's not out of the kindness of our hearts that we help. Heck, I don't know what it is. Probably I just like reading my own drivel on the internet and occassionally helping others is a good excuse. Lol !-) +1 OTQOTW -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse a String?
Gregory Piñero wrote: Is my mind playing tricks on me? I really remember being able to reverse a string as in: text='greg' print text.reverse() 'gerg' That method has never existed AFAIK. Maybe you're thinking of the reverse() method on lists? In any case, the you can reverse strings in a couple of ways: ''.join(reversed('foo')) 'oof' 'foo'[::-1] 'oof' -- http://mail.python.org/mailman/listinfo/python-list
Re: something for itertools
George Sakkis a écrit : Daniel Nogradi wrote: In a recent thread, http://mail.python.org/pipermail/python-list/2006-September/361512.html, a couple of very useful and enlightening itertools examples were given and was wondering if my problem also can be solved in an elegant way by itertools. I have a bunch of tuples with varying lengths and would like to have all of them the length of the maximal and pad with None's. So something like a = ( 1, 2, 3 ) b = ( 10, 20 ) c = ( 'x', 'y', 'z', 'e', 'f' ) should turn into a = ( 1, 2, 3, None, None ) b = ( 10, 20, None, None, None ) c = ( 'x', 'y', 'z', 'e', 'f' ) Of course with some len( ) calls and loops this can be solved but something tells me there is a simple itertools-like solution. Any ideas? Not the most readable one-liner of all times, but here it goes: a,b,c = zip(*map(None,a,b,c)) Simple and beautiful - but effectively requires a comment to explain what's going on !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse a String?
That 'foo'[::-1] is the Python reverse string idiom I'll try here forward, thanks. Also '.h.e.l.l.o'[1::2] to pick out every second char, etc., thanks. Three footnotes: 1) Reverse string isn't yet in http://www.python.org/doc/faq/ 2) Google Groups searches here yesterday instead pushed me towards the less concise: def reverse(chars): aa = array.array('c', chars) aa.reverse() return aa.tostring() 3) I went looking when first I found time to rethink what I had been running this past year: def reverse(chars): ochars = '' beyond = len(chars) for ix in range(beyond): ochars += chars[beyond - 1 - ix] return ochars -- http://mail.python.org/mailman/listinfo/python-list
Re: Global module variables as default parameters
Thanks to all who answered. On Friday 22 September 2006 17:28, Marc 'BlackJack' Rintsch wrote: Christoph Haas wrote: TestModule.py globalvar = 0 def def1(): print globalvar def def2(foo=globalvar): print foo Running the test.py script prints 123 and 0. So accessing the globalvar in def1() works. But if I try to use the global variable as a default parameter in def2() it uses the default 0. What is the difference between these two? Are there contexts of default parameters? Default parameters are evaluated *once* when the ``def`` is executed. So in `def2` the value of `foo` won't be looked up when calling the function as it is already bound to the value 0. Now that you point me to it it's pretty obvious indeed. I always forget that the 'def's are executed at load time, too. Peter/John: in fact I already used a sentinel like you proposed as a workaround. So there is just one sensible way to do it. Again. Kindly Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse a String?
On 9/23/06, Robert Kern [EMAIL PROTECTED] wrote: Not in that form, no, since this already exists: text[::-1] Wow, that's really cool! Here are my questions: 1. How long has this thing been going on? I didn't know slice even took an extra argument like that. 2. Where can I get the lowdown on everything there is to know about slice? Since I've obviously been living in ignorance all these years! Thanks again, Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Isn't bool __invert__ behaviour strange?
MonkeeSage wrote: The C++ standard provides _operator keywords_ (Fig. 21.8) that can be used in place of several C++ operators. (Deitel Deitel, 2001; 1082). Thanks. Only if I'd known that earlier ;) Regards, Björn -- BOFH excuse #39: terrorist activities -- http://mail.python.org/mailman/listinfo/python-list