Getting a stable virtual env
Hi ppl, I'm trying to figure out the whole virtualenv story. Right now I'm using it to creating an environment for our upcoming debian upgrade to squeeze. I'm doing some tests in our current distrib (python 2.5). I have come to realize that a lot of packages in the version I'm interested in are not available anymore on pypi. The pip installer fails a lot. Squeeze features python 2.7 so I'm pretty sure that everything will work fine. I've actually tested it. The question is, how do I protect myself from future package removal ? Do I absolutely need to run a local pypi server (I've seen some python package doing this), and mirror all the packages I'm interested in ? cheers, JM -- https://mail.python.org/mailman/listinfo/python-list
cross-compiling python-2.5.1 for PPC, error in Modules/unicodedata.o
not sure if this is the right list for this, but it's a starting point. i'm using a wind river linux development environment to build a full system for a powerpc board, and that includes cross-compiling python-2.5.1 for ppc. the compile fails thusly: powerpc-wrs-linux-gnu-ppc_e500v2-glibc_std-gcc -shared Modules/unicodedata.o -o Modules/unicodedata.so Modules/unicodedata.o: file not recognized: File truncated collect2: ld returned 1 exit status Makefile:1159: *** [Modules/unicodedata.so] Error 1 ... snip ... #0 Modules/unicodedata.so at /home/rpjday/workspace/8548_prj/build/python-2.5.1/BUILD/Python-2.5.1/Makefile:1159 #1 oldsharedmods at /home/rpjday/workspace/8548_prj/build/python-2.5.1/BUILD/Python-2.5.1/Makefile:440 #2 all at /home/rpjday/workspace/8548_prj/build/python-2.5.1/BUILD/Python-2.5.1/Makefile:353 Command-line arguments: "OPT=-g -O2 -fomit-frame-pointer -pipe -g -O2 -fomit-frame-pointer -pipe -D_GNU_SOURCE -fPIC -I=/usr/include -I=/home/rpjday/workspace/8548_prj/host-cross/powerpc-wrs-linux-gnu/sysroot/usr/include/krb5 DESTDIR=/home/rpjday/workspace/8548_prj/host-cross/powerpc-wrs-linux-gnu/sysroot/usr/lib/../.. HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen" error: Bad exit status from /home/rpjday/workspace/8548_prj/build/python-2.5.1/rpm-tmp.86223 (%build) ... snip ... you can see that the file Modules/unicodedata.o is flagged as not recognized. in fact, it exists but is empty. i'm going to continue digging around but i'm open to suggestions. i also have the full 1700 lines of output from the beginning of the cross-compile if anyone wants to see it. thanks, and is there a more appropriate place to ask this? rday -- ======== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday -- http://mail.python.org/mailman/listinfo/python-list
error compiling python, and "plat-linux2" versus "plat-linux3"
i may have asked about this once upon a time but i'm still fighting with it so i'll throw myself on the mercy of the list and ask again. (and if there's a better forum for this question, let me know.) i'm using the development environment wind river linux 4.2 (hereafter just "WRL") to configure and build an entire embedded system, and that build is failing when it comes to compile python-2.6.2. i *think* i have an idea what the general problem is, but i need help to narrow it down. here's the tail end of the build process: = begin snippet = Checking for unpackaged file(s): /home/rpjday/WindRiver/projects/42/glibc_std/host-cross/bin/../lib64/rpm/check-files /home/rpjday/WindRiver/projects/42/glibc_std/build/INSTALL_STAGE/python-2.6.2 error: Installed (but unpackaged) file(s) found: /usr/lib64/python2.6/plat-linux3/IN.py /usr/lib64/python2.6/plat-linux3/IN.pyc /usr/lib64/python2.6/plat-linux3/IN.pyo /usr/lib64/python2.6/plat-linux3/regen RPM build errors: File not found: /home/rpjday/WindRiver/projects/42/glibc_std/build/INSTALL_STAGE/python-2.6.2/usr/lib64/python2.6/plat-linux2 Installed (but unpackaged) file(s) found: /usr/lib64/python2.6/plat-linux3/IN.py /usr/lib64/python2.6/plat-linux3/IN.pyc /usr/lib64/python2.6/plat-linux3/IN.pyo /usr/lib64/python2.6/plat-linux3/regen /home/rpjday/WindRiver/projects/42/glibc_std/scripts/packages.mk:2661: *** [python.install] Error 1 /home/rpjday/WindRiver/projects/42/glibc_std/scripts/packages.mk:3017: *** [python.buildlogger] Error 2 /home/rpjday/WindRiver/projects/42/glibc_std/scripts/Makefile.common.epilogue:37: *** [all] Error 2 GNUmakefile:55: *** [all] Error 2 #0 all at /home/rpjday/WindRiver/projects/42/glibc_std/build/GNUmakefile:55 remake[2]: Leaving directory `/home/rpjday/WindRiver/projects/42/glibc_std/build' Command-line arguments: "all" Makefile:831: *** [all-recursive] Error 1 #0 all-recursive at /home/rpjday/WindRiver/projects/42/glibc_std/Makefile:831 remake[1]: Leaving directory `/home/rpjday/WindRiver/projects/42/glibc_std' Command-line arguments: "all-recursive" make: *** [all] Error 2 = end snippet = note the references to "plat-linux3" above -- i think that's what's killing me as i'm doing all this on a ubuntu 11.04 system with my own hand-rolled 3.x kernel and i think there's a step in the python build process that can't handle a running kernel with version "3.*". this is my suspicion as i've already found another location in the WRL build that clearly never imagined it would be run on a 3.x kernel (it recognized only "2.x" kernels as a hardcoded value.) another reason i think it's something like this is if i run just the prep step -- that is, untar the python-2.6.2 tarball and apply the WRL patches -- here's what i get in the resulting directory: $ grep -r plat-linux2 * Doc/install/index.rst: ['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2', Doc/install/index.rst:'/www/python/lib/pythonX.Y/plat-linux2', ...]``. Misc/RPM/python-2.6.spec:%{__prefix}/%{libdirname}/python%{libvers}/plat-linux2 Misc/HISTORY: * Lib/plat-sunos5/CDIO.py, Lib/plat-linux2/CDROM.py: Misc/HISTORY:e.g. lib-tk, lib-stdwin, plat-win, plat-linux2, plat-sunos5, dos-8x3. $ as you can see, it's all *hardcoded* references to "plat-linux2" so it's a mystery as to where the references to "plat-linux3" are coming from during the build process, which is why i suspect the reason i gave above -- that nothing took into account that this build would be done on a 3.x kernel. can anyone shed light on this? can anyone else *try* this on a system with a 3.x kernel and let me know what they get? i'm about to just hack the source and change that to "plat-linux3" to see what happens, but it would be nice to do something more intelligent. thanks. rday -- Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: A beginner's problem...
On Wed, 15 Dec 2004, Amir Dekel wrote: > Hello everyone, > > First, I have to say that Python is one of the coolest programing languages I > have seen. > And now for the problem (must be a silly one): > When I import a module I have wrote, and then I find bugs, it seems that I > can't import it again after a fix it. It always shows the same problem. I try > del module but it doesn't work. > (I use Python 2.4 with the ActivePython pack (PythonWin IDE) > > Solution anyone? reload? rday -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for wget-like module for getching software
On Thu, 16 Dec 2004, Stefan Behnel wrote: > > Robert P. J. Day schrieb: > > that is, i can just say, "go get file gcc-3.4.2.tar.bz2", and start > > searching at "ftp://pub.gnu.org/pub/gcc";. i may not know how far down > > in the directory structure that file is, but wget will happily search > > recursively until it finds it. > > That sounds pretty inefficient and should produce some load on the > server side. Imagine everyone doing that. Many FTP-servers provide > files like "ls-R.gz" somewhere, meaning, a list of files and > directories. i realize that and, as much as possible, i try to start the process with what i *know* is the actual directory location. but occasionally, if i can't guarantee an exact directory, i just want the option to start a bit higher up the directory structure. i wasn't going to make a habit of it, it's more an absolute last resort, if it comes down to it. > And then, there's Google. Why do you have to use FTP? Ask Google for > "yourfile.tar.bz2 site:the.domain.name". It will very likely return > a suitable URL for you that you can use for download. Just tried it > with "site:ftp.gnu.org gcc-3.4.2.tar.bz2" - works. You can even use > that link and try to replace "http://"; with "ftp://"; for download. > Should work for many source repositories. > > You can use urllib2 for both querying and download. and that pretty much answers the question i had. much thanks. and now that i have my answer, i might have to unsubscribe. you guys sure are a chatty bunch. :) rday p.s. just kidding. -- http://mail.python.org/mailman/listinfo/python-list
looking for wget-like module for getching software
just getting started with python, and i'm designing a program for fetching software from the net, given the package name, version number and/or date stamp, download method (tarball, CVS, etc.) and so on. i've already got a shell script doing this, but python would certainly clean up the code a lot. first question -- does such a utility/module (or something like it) already exist? that is, with the ability to say, "go get me gcc, version 3.4.3, as a tarball"? or "go get me glibc, CVS date stamp , from that CVS repo"? as for the second question, the driving force behind a fair bit of the current program is "wget", which has the ability to search recursively and bring back a file of a given name (which "curl" doesn't appear to have). that is, i can just say, "go get file gcc-3.4.2.tar.bz2", and start searching at "ftp://pub.gnu.org/pub/gcc";. i may not know how far down in the directory structure that file is, but wget will happily search recursively until it finds it. so, any pointers to python utils/modules that do any or all of the above? thanks. rday -- http://mail.python.org/mailman/listinfo/python-list
Re: Manipulating MySQL Sets
On Sun, 13 Dec 2009, Victor Subervi wrote: > On Sun, Dec 13, 2009 at 11:36 AM, Carsten Haese > wrote: > > I don't know what I'm expecting! > > That statement is the most succinct summary of the root cause of all > your problems. If you don't know what to expect, how could you > possibly write code that produces what you expect? (Don't answer > this question. It's a rhetorical question.) http://twitter.com/rpjday/status/6576145809 rday -- ==== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: Manipulating MySQL Sets
On Sun, 13 Dec 2009, Victor Subervi wrote: > On Sun, Dec 13, 2009 at 11:56 AM, Robert P. J. Day > wrote: > On Sun, 13 Dec 2009, Victor Subervi wrote: > > > On Sun, Dec 13, 2009 at 11:36 AM, Carsten Haese > > > wrote: > > > I don't know what I'm expecting! > > > > That statement is the most succinct summary of the root cause > of all > > your problems. If you don't know what to expect, how could you > > possibly write code that produces what you expect? (Don't > answer > > this question. It's a rhetorical question.) > > http://twitter.com/rpjday/status/6576145809 > > > Indeed. Specification, however, is as much art as it is science. Are > you a better programmer today than your first day programming? Have > you learned how to specify better in the process? More rhetorical > questions ;) it's sunday, i have beer and there's an NFL game on soon. do not ask tough questions. that is all. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: can i examine the svn rev used to build a python 3 executable?
On Tue, 19 Jan 2010, Robert P. J. Day wrote: > i'm currently checking out python3 from the svn repo, configuring, > building and installing under /usr/local/bin on my fedora 12 system, > all good. > > i'm curious, though -- is there a query i can make of that > executable that would tell me what svn rev it was built from? i'm > guessing not, but i thought i'd ask. never mind. just discovered that while "python3 -V" won't do it, executing it gives me: $ python3 Python 3.2a0 (py3k:77609, Jan 19 2010, 04:10:16) ... and it's that 77609 rev number i was after. rday -- ======== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
can i examine the svn rev used to build a python 3 executable?
i'm currently checking out python3 from the svn repo, configuring, building and installing under /usr/local/bin on my fedora 12 system, all good. i'm curious, though -- is there a query i can make of that executable that would tell me what svn rev it was built from? i'm guessing not, but i thought i'd ask. rday -- ==== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
how to check if a module is importable?
finally getting back to clawing my way thru the python 3 book so probably a number of newbie questions coming up. first one -- can i check if a module is importable (equivalently, exists on sys.path, i assume) without trying to import it first? i can see that i can use try/except and just run "import" -- is that the accepted way to test? rday -- ==== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
examining an initial, pristine python3 shell session
still working my way through "dive into python 3" and i've already been asked to give a newbie tutorial on it -- blind leading the blind, as it were. that should be hilarious. i'll be using python 3 and it occurred to me that it would be educational (at least for me :-) to display what an initial p3 shell session looks like before doing any imports whatsoever. as in, i run "python3" on my fedora box and, at the ">>>" prompt, i want to show what's already there for the new user. from what little i know so far, i'd start with: >>> __name__ '__main__' >>> to display the name of the current scope(?). backing up a bit, i could run either of: >>> dir() ['__builtins__', '__doc__', '__name__', '__package__'] >>> globals() {'__builtins__': , '__name__': '__main__', '__doc__': None, '__package__': None} >>> then i might go a bit further to examine some of *those* objects. i admit it might seem a bit dry, but i think it would be handy to have a handle on what a clean shell session looks like before starting to import things, then seeing how that importing changes the session before getting down to actual programming. what other useful commands might i run immediately after starting a session whose output would be informative? i can certainly poke at some of those objects to see them in more detail. i'm just curious what others might recommend. thanks. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: how to check if a module is importable?
On Thu, 21 Jan 2010, Lie Ryan wrote: > On 01/20/10 19:58, Robert P. J. Day wrote: > > > > finally getting back to clawing my way thru the python 3 book so > > probably a number of newbie questions coming up. first one -- can i > > check if a module is importable (equivalently, exists on sys.path, i > > assume) without trying to import it first? > > > > i can see that i can use try/except and just run "import" -- is that > > the accepted way to test? > > check imp.find_module() thanks, that's what i was looking for. i'm sure i'll run across that shortly as i keep working my way thru this python 3 book. rday -- ==== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: examining an initial, pristine python3 shell session
On Wed, 20 Jan 2010, Alf P. Steinbach wrote: > * Robert P. J. Day: ... snip ... > > what other useful commands might i run immediately after > > starting a session whose output would be informative? i can > > certainly poke at some of those objects to see them in more > > detail. i'm just curious what others might recommend. thanks. > > That depends on what you mean by "newbie". > > If it's someone who knows a little bit of programming but is new to > Python, then 'help' would definitely be about the first thing I'd > show her. > > But if it's someone who doesn't even know anything about > programming, then I'd recommend (blatant plug) http://tinyurl.com/programmingbookP3> -- its first two chapters are > constructed around complete, concrete examples. However, you would > have to adapt just the *sense* of the first chapter, which is only > about tool usage, to *nix, since it's written for Windows. I'd not > dive into 'help' for the someone who doesn't know anything because > it gets technical pretty fast, and because she will get back to that > on her own when it's time. > > Whatever you do, and whatever the background of the newbie, do > introduce turtle graphics right away. ah, thank you, i appreciate that reference. i'm expecting the small audience to be relatively tech-savvy with OO dev experience, and i'm betting that some of them will be wondering right off the very first thing *i* was wondering -- when i start that python3 shell and get dumped into it, what am i looking at? which is why i wanted to collect a few commands to give the attendees at least a vague idea of what was already there. i've collected the following to start with: >>> dir() ['__builtins__', '__doc__', '__name__', '__package__'] >>> globals() ... stuff ... then move on to examine *those* things: >>> type(dir) >>> type(globals) >>> type(__builtins__) zoom in a bit further and pick on specific examples: >>> dir(__builtins__) ... lots of output ... and so on. as i said, i know it looks dry but i figure i can take 5 minutes or so just to lay out the terrain and what a shell session looks like before you do *anything* with it. and i'm betting most of my audience will appreciate getting that high-level view before launching into some programming. they'll just want to know the initial session setup before they start importing stuff into it. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
deleting, then re-importing a class method
(once again, never ashamed to ask the dumb questions.) still playing with python3, and testing whether i can delete/unimport a specific method, then re-import it: >>> import sys >>> print(sys.__doc__) ... blah blah blah ... >>> del(sys.__doc__) >>> print(sys.__doc__) module(name[, doc]) Create a module object. The name must be a string; the optional doc argument can have any type. >>> ok, now that i've deleted just that member of "sys", can i re-import it? i know this doesn't seem to work: >>> import sys or is there an operator other than "import" that more represents a full refresh of a class? rday p.s. no, i don't have a valid application of the above, i'm just trying to break things. -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
how to list the attributes of a class, not an object?
once again, probably a trivial question but i googled and didn't get an obvious solution. how to list the attributes of a *class*? eg., i was playing with dicts and noticed that the type returned by the keys() method was "dict_keys". so i'm now curious as to the attributes of the dict_keys class. but i don't know how to look at that without first *creating* such an instance, then asking for "dir(dk)". surely there's a simpler way just using the class name, no? rday p.s. any recommendations for the most concise reference sheet for python 3 that exists? being able to print off the entire language spec on two or four pages and tacking it up in front of me would be just ducky. thanks. -- ==== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: how to list the attributes of a class, not an object?
On Sun, 24 Jan 2010, Alf P. Steinbach wrote: > * Robert P. J. Day: > > once again, probably a trivial question but i googled and didn't > > get an obvious solution. how to list the attributes of a *class*? > > > > eg., i was playing with dicts and noticed that the type returned by > > the keys() method was "dict_keys". so i'm now curious as to the > > attributes of the dict_keys class. but i don't know how to look at > > that without first *creating* such an instance, then asking for > > "dir(dk)". > > Like, > > dir( list ) > > where 'list' is the built-in type. > > There's a pretty-printer for that somewhere, but I can't recall. except that doesn't work for >>> dir(dict_keys) so what's the difference there? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
listing an object's methods/attributes?
getting back into python after a long hiatus and "diving" into python 3 (http://www.diveintopython3.org/), but i can't remember how to list an object's full set of methods or attributes. how does that go again? rday -- ==== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
why does "help(import)" not work?
i'm sure there's a painfully obvious answer to this, but is there a reason i can't do: >>> help(import) File "", line 1 help(import) ^ SyntaxError: invalid syntax >>> on the other hand, i can certainly go into "help()" and type "import" to get that help. it seems counter-intuitive to have the first variation fail but the second succeed. what is the rule for this in python3? rday -- ======== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: Program to compute and print 1000th prime number
On Sat, 7 Nov 2009, sstein...@gmail.com wrote: > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > I am taking the MIT online course Introduction to Computer Science and > Programming. I have a assignment to write a program to compute and print > the 1000th. prime number. Can someone give me some leads on the correct > code? Thanks, Ray > > > Copying code != doing an assignment. Try Knuth. i was going to say much the same, but it's also worth pointing out that, using standard techniques, there is no straightforward way to print the n'th prime number, given some initial value of n. the ubiquitous sieve of eratosthenes requires you to pre-specify your maximum value, after which -- once the sieve completes -- all you know is that you have all of the prime numbers up to n. whether you'll have 1000 of them isn't clear, which means that you might have to start all over with a larger maximum value. (being able to directly determine the n'th prime number would solve a *lot* of prime number problems. :-) and given that one can google and, in seconds, have the solution, i feel no guilt in referring to http://code.activestate.com/recipes/366178/. rday -- ======== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: Program to compute and print 1000th prime number
On Sat, 7 Nov 2009, Raymond Hettinger wrote: > > > On Nov 7, 2009, at 9:44 AM, Ray Holt wrote: > > > > > I am taking the MIT online course Introduction to Computer > > > Science and Programming. I have a assignment to write a > > > program to compute and print the 1000th. prime number. Can > > > someone give me some leads on the correct code? Thanks, > > > Ray > > Tongue in cheek solution: > > import urllib2 > > url = 'http://primes.utm.edu/lists/small/1.txt' > primes = [] > for line in urllib2.urlopen(url).read().splitlines(): > values = line.split() > if len(values) == 10: > primes.extend(values) > print primes[1000-1] reminds me of a variation of an old joke: using nothing but this barometer, determine the height of that building. answer: go to the building manager and say, "i'll give you this really neat barometer if you tell me how tall this building is." rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
how to display the return type of an os method?
once again, a thoroughly newbie question but what's the quickest way to display the return type of, say, os.stat()? i can obviously do this in two steps: >>> x=os.stat('/etc/passwd') >>> type(x) >>> i'd just like to see that os.stat() returns a posix.stat_result object in one line. how dumb a question is that? rday -- ======== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the best way to delete strings in a string list that that match certain pattern?
On Sat, 7 Nov 2009, Peng Yu wrote: > On Fri, Nov 6, 2009 at 5:57 PM, Dave Angel wrote: > > But if you have an expression you want to match each dir against, > > the list comprehension is the best answer. And the trick to > > stuffing that new list into the original list object is to use > > slicing on the left side. The [:] notation is a default slice > > that means the whole list. > > > > dirs[:] = [ item for item in dirs if bool_expression_on_item ] > > I suggest to add this example to the document of os.walk() to make > other users' life easier. huh? why do you need the slice notation on the left? why can't you just assign to "dirs" as opposed to "dirs[:]"? using the former seems to work just fine. is this some kind of python optimization or idiom? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: how to display the return type of an os method?
On Sat, 7 Nov 2009, Bruno Desthuilliers wrote: > Robert P. J. Day a écrit : > > once again, a thoroughly newbie question but what's the quickest way > > to display the return type of, say, os.stat()? i can obviously do > > this in two steps: > > > >>>> x=os.stat('/etc/passwd') > >>>> type(x) > > > > > > i'd just like to see that os.stat() returns a posix.stat_result > > object in one line. > > => type(os.stat('/etc/passwd')) > > But reading the doc might help too: > > => help(os.stat) never mind, i realize now it was a dumb question since the return type is based on the routine logic, of course. argh. carry on. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: My own accounting python euler problem
On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: $300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the > $200 and $100. In other words, there is more than one solution to > the problem. > > My first question is: 1. given a list of invoives I=[500, 400, 450, > 200, 600, 700] and a check Ch=600 how can I print all the different > combinations of invoices that the check is possibly cancelling that sounds like the classic knapsack problem: http://www.itl.nist.gov/div897/sqg/dads/HTML/knapsackProblem.html it's NP-complete. rday -- ======== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: My own accounting python euler problem
On Sat, 7 Nov 2009, vsoler wrote: > In the accounting department I am working for we are from time to > time confronted to the following problem: > > A customer sends us a check for a given amount, but without > specifying what invoices it cancels. It is up to us to find out > which ones the payment corresponds to. > > For example, say that the customer has the following outstanding > invoices: $300, $200, $50; and say that the check is for $250. This > time it is clear, the customer is paying bills $200 and $50. > > However, let's now say that the outstanding invoices are $300, $200, > $100 and that the check is for $300. In this case there are already > two possibilities. The customer is paying the $300 invoice or the > $200 and $100. In other words, there is more than one solution to > the problem. > > My first question is: > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > check Ch=600 > how can I print all the different combinations of invoices that the > check is possibly cancelling by the way, there's a bit more to it than just seeing if you can match the cheque amount exactly. some python solutions are here: http://rosettacode.org/wiki/Knapsack_Problem and a general solution allows you to place different "values" on which items you pack into your knapsack. say a customer has outstanding invoices for 200, 400 and 600, and you get a cheque for 600. what do you apply that against? the single invoice for 600, or the two for 200 and 400? that depends. if all invoices have the same "value", it won't matter. but if the invoice for 600 just went out, while the two others are just about to become, say, overdue so that a penalty is about to be applied, your customer would probably *really* appreciate it if you applied that cheque to the older invoices. in general, then, you can not only see what matches exactly but, for the sake of your customer, you can give higher value to paying off older invoices. that's how the general knapsack problem works. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: My own accounting python euler problem
On Sun, 8 Nov 2009, Ozz wrote: > > Hi, > > > My first question is: > > 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a > > check Ch=600 > > how can I print all the different combinations of invoices that the > > check is possibly cancelling > > Incidentally, I'm currently learning python myself, and was working > on more or less the same problem as an exercise; > > For listing all different subsets of a list (This is what I came up > with. Can it be implemented shorter, btw?): > > def subsets(L): > S = [] > if (len(L) == 1): > return [L, []] > else: > for s in subsets(L[1:]): > S.append(s) > S.append(s + [ L[0]]) > return S > > Now, to use the above piece of code (after 'import subset'): > > >>> subset.subsets([4,7,8,2]) > [[2], [2, 4], [2, 7], [2, 7, 4], [2, 8], [2, 8, 4], [2, 8, 7], [2, 8, 7, 4], > [], [4], [7], [7, 4], [8], [8, 4], [8, 7], [8, 7, 4]] > >>> map(sum,subset.subsets([4,7,8,2])) > [2, 6, 9, 13, 10, 14, 17, 21, 0, 4, 7, 11, 8, 12, 15, 19] > > It's not a real solution yet, and as others have pointed out the > problem is NP complete but it might help to get you going. does your solution allow for the possibility of different invoices of equal amounts? i would be reluctant to use the word "subset" in a context where you can have more than one element with the same value. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
python simply not scaleable enough for google?
http://groups.google.com/group/unladen-swallow/browse_thread/thread/4edbc406f544643e?pli=1 thoughts? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
starting with python 3.1 vs 3.2, and "test_telnetlib"
a couple short questions. on my primary linux distro -- fedora -- python 2.x is going to be around for quite some time, but if some folks want to *start* programming in python, it seems reasonable to just co-install python 3.x and let them cut their teeth on that, invoking it with "python3". does that make sense as there seems to be little value in getting started on python 2.x. and in terms of installing python 3.x, just for fun, i used "svn" to check out the two relevant repositories: * release31-maint (for 3.1) * py3k (for 3.2) since i figured, if people are going to be using this strictly for hacking around, i can live life on the edge. however, on my f11 system, doing the configure/make/make test sequence, the 3.1 maintenance release failed two tests: multiprocessing and telnetlib, while the 3.2 branch failed only the telnetlib test. i've checked and, apparently, that telnetlib test failure has been around for a while. is there a tweak i can make to the configure and/or make to avoid that test? it would be nice to resolve it as it's the only test out of 315 that failed for me. rday p.s. the test output for telnetlib on the py3k (3.2) branch: test_telnetlib test test_telnetlib failed -- Traceback (most recent call last): File "/home/rpjday/python3/svn/3.2/py3k/Lib/test/test_telnetlib.py", line 470, in test_debuglevel_reads self._test_debuglevel([a, EOF_sigil], b) File "/home/rpjday/python3/svn/3.2/py3k/Lib/test/test_telnetlib.py", line 451, in _test_debuglevel txt = telnet.read_all() File "/home/rpjday/python3/svn/3.2/py3k/Lib/telnetlib.py", line 325, in read_all self.fill_rawq() File "/home/rpjday/python3/svn/3.2/py3k/Lib/telnetlib.py", line 516, in fill_rawq buf = self.sock.recv(50) socket.error: [Errno 104] Connection reset by peer i'm not running telnet on this host, and i have no intention of doing so -- it's all ssh, of course. is that what this test error is complaining about -- that it can't find a listening telnet server? -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list
Re: Code for finding the 1000th prime
On Sun, 15 Nov 2009, mrholtsr wrote: > I am absolutely new to python and barely past beginner in programming. > Also I am not a mathematician. Can some one give me pointers for > finding the 1000th. prime for a course I am taking over the internet > on Introduction to Computer Science and Programming. Thanks, Ray it's 7919. rday -- ======== Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- http://mail.python.org/mailman/listinfo/python-list