Re: [Tutor] os.listdir fn
Are you sure this does what you want? You compute 'scripts' and 'filenames' and throw them away. I think this function will return the base name of all the files *and folders* in ./icon.scripts/opname. If you are trying to return the base name of every file or directory whose extension is '.script', you can use a list comprehension to filter the list: def createaproposjlist(opname): filelist=os.listdir('./icon.scripts/'+opname) spltnames=map(os.path.splitext,filelist) return [ name for name, ext in spltnames if ext == '.script' ] If you are concerned about directories with names ending in '.script' then add another filter using os.path.isdir: def createaproposjlist(opname): basedir = './icon.scripts/'+opname filelist=os.listdir(basedir) filelist = [ f for f in filelist if os.path.isfile(os.path.join(basedir, f)) ] spltnames=map(os.path.splitext,filelist) return [ name for name, ext in spltnames if ext == '.script' ] Kent Nandan wrote: It does if you use the glob module :-) Python, with batteries included. But sometimes finding the right battery can be challenging... Muttering 'globbing is a Perl concept, listing dirs must be in file ops' I turned first to the Files section of the Nutshell book :-) But I came up with this code, which I'm happy with for several reasons: def createaproposjlist(opname): filelist=os.listdir('./icon.scripts/'+opname) spltnames=map(os.path.splitext,filelist) scripts=filter(lambda x: x[1]=='.script', spltnames) filenames=map(''.join,scripts) filebases=map(lambda x: x[0], spltnames) return filebases; Cheers, Nandan ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
[Tutor] Any Math Modules ?
I am currently updating the DMOZ section of: http://www.dmoz.org/Computers/Programming/Languages/Python/Modules/Math_and_Calculations/ If anyone has some useful python packages for math that are not listed in DMOZ, please let me know. It makes life much easier if your code can be found by search engines. ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Re: Could I have used time or datetime modules here?
Liam Clarke wrote: As far as I know, you'll either have to - run Python 2.3 or - run Python 2.3 until they release a new version of Pygame, Yes, any Python addon that uses .pyd or .dll files has to be recompiled for Python2.4. Pygame has many .pyd files so you have to use Python 2.3. Here is a thread on comp.lang.python that explains why... http://tinyurl.com/659mk Kent ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
[Tutor] function that returns a fn
I'm looking for resources to help me with a fn that returns a fn after binding one of its arguments (aka currying, like the bind1st of C++) Considering Python syntax is quite straightforward, this is my first try: def getjlistrenderer(opname): def listrender(): # use opname, eg ops=getlist(opname) # or set local fn variable return renderer; return listrender; #?or f=listrender(); return f; Is it really as simple as this? Or will I always return the same function definition? I need it to return a 'new' function for each call to getjlistrender() .. do I need to create a new fn with f=listrender() ? Any pointers to pages/books etc. appreciated. I am looking through my books too, but thought I'd get some more pointers as well. Web searching so far only shows lambda, which is one-liner, and that won't do. Thanks! -- Nandan Bagchee We need a language that lets us scribble and smudge and smear, not a language where you have to sit with a teacup of types balanced on your knee and make polite conversation with a strict old aunt of a compiler. -- Paul Graham ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
[Tutor] Pygame problems
I am not sure if this is the right place, apologies if not. Anyway in a game I wrote using pygame, I would like to increase the initial message so it is over several lines. This is the code in the example game if pygame.font: font = pygame.font.Font(None, 36) text = font.render("Pummel The Chimp, And Win $$$", 1, (10, 10, 10)) textpos = text.get_rect(centerx=background.get_width()/2) background.blit(text, textpos) Now how can I get this to be on more than one line and bigger (for my simple game I need a much more detailed explanation). ___ Win a castle for NYE with your mates and Yahoo! Messenger http://uk.messenger.yahoo.com ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] function that returns a fn
Yes, it really is that simple. :-) A common example is a function that makes a function which adds a constant to its argument: >>> def makeadder(n): ... def adder(x): ... return x + n ... return adder ... Make a function that adds 3 to its argument...note there is no special syntax for the return, just assign to a name >>> add3 = makeadder(3) add3 is a function: >>> add3 >>> add3(4) 7 Make another function to add 5: >>> add5 = makeadder(5) >>> add5(10) 15 add3 still works, it is a separate function with its own binding of n: >>> add3(2) 5 Kent Nandan wrote: I'm looking for resources to help me with a fn that returns a fn after binding one of its arguments (aka currying, like the bind1st of C++) Considering Python syntax is quite straightforward, this is my first try: def getjlistrenderer(opname): def listrender(): # use opname, eg ops=getlist(opname) # or set local fn variable return renderer; return listrender; #?or f=listrender(); return f; Is it really as simple as this? Or will I always return the same function definition? I need it to return a 'new' function for each call to getjlistrender() .. do I need to create a new fn with f=listrender() ? No, this is a call to listrender, it will return the renderer object not a function. Any pointers to pages/books etc. appreciated. I am looking through my books too, but thought I'd get some more pointers as well. Web searching so far only shows lambda, which is one-liner, and that won't do. There are several currying recipes in the Python Cookbook: http://aspn.activestate.com/ASPN/search?query=curry&x=0&y=0§ion=PYTHONCKBK&type=Subsection Searching the cookbook for 'closure' also gives some recipes that might be of interest. Kent Thanks! ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
[Tutor] Re: Pygame problems
I am not sure if this is the right place, apologies if not. http://pygame.org/ http://pygame.org/info.shtml#maillist Now how can I get this to be on more than one line and bigger (for my simple game I need a much more detailed explanation). http://mu.arete.cc/pcr/ http://mu.arete.cc/pcr/proj/textrect I also have a wrapped-text object in pygsear: http://www.nongnu.org/pygsear/ http://www.nongnu.org/pygsear/doc/api_html/public/pygsear.Util-module.html#render_textrect _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] PDF and Python
Hi, If you only want to convert text files, this tool I wrote may be even easier than using ReportLab: http://sourceforge.net/projects/xtopdf It is based on ReportLab. You can use it both as a standalone command-line tool, to convert a single text file to PDF. Run PDFWriter.py. You can easily modify the code to convert more than one file, or just write a shell script / .BAT/.CMD file to call it in a loop). You can also use it progammatically from your Python programs. Both procedural and object-oriented versions are available. Look at WritePDF.py and PDFWriter.py. Look at PDFBook.py for an example of usage of this tool to create a simple PDF book from a set of text files representing chapters. HTH Az --- Jason Child <[EMAIL PROTECTED]> wrote: > Hey there. Does anyone know of a way to output PDFs > with python? I have some > data that I have processed from a series of > textfiles that I would like to > provide PDF format reports for.. > > Jason Christopher Child > > Computer Network Services Professionals > Tech Support > 505-986-1669 > 1-877-321-9165 > [EMAIL PROTECTED] > > VOZ Online > VOIP Install Tech > 505-428-7500 > 1-877-428-7550 > > ___ > Tutor maillist - [EMAIL PROTECTED] > http://mail.python.org/mailman/listinfo/tutor > __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor